Inherited test methods do not get expected group behavior
See original GitHub issueConsider the following test classes:
@Test
public abstract class ParentTest {
public void parentTestMethod() {
}
}
@Test(groups = "myGroup")
public class ChildTest extends ParentTest {
public void childTestMethod() {
}
}
When running this test (ChildTest), I would expect that both test methods (childTestMethod and parentTestMethod) belong to group ‘myGroup’. Apparently this is not the actual behavior (tested with version 6.4).
I put together some code to investigate this issue:
TestNGMethodFinder testNGMethodFinder = new TestNGMethodFinder(new RunInfo(), new JDK15AnnotationFinder(new DefaultAnnotationTransformer()));
ITestNGMethod[] testMethods = testNGMethodFinder.getTestMethods(ChildTest.class, new XmlTest());
for (ITestNGMethod testMethod : testMethods) {
String[] groups = testMethod.getGroups();
System.out.println(testMethod + " groups:" + Arrays.toString(groups));
}
Output from running this code:
ChildTest.childTestMethod()[pri:0, instance:null] groups:[myGroup]
ParentTest.parentTestMethod()[pri:0, instance:null] groups:[]
I looked into the TestNG source code, and it appears that this behavior originates from the method org.testng.internal.BaseTestMethod#initGroups(Class<?>). To be exact, I think the following statement is the cause of this rather odd behavior:
ITestOrConfiguration classAnnotation = (ITestOrConfiguration) getAnnotationFinder().findAnnotation(getMethod().getDeclaringClass(), annotationClass);
In order to fix this issue, this statement could be modified to:
ITestOrConfiguration classAnnotation = (ITestOrConfiguration) getAnnotationFinder().findAnnotation(getInstance().getClass(), annotationClass);
but I am not sure if this would be the correct way to resolve the issue. Nor eventual implications…
Issue Analytics
- State:
- Created 12 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
jasmine spies on inherited methods (with typescript) not ...
In my tests for the class Husband, i'm only concerned of testing the logic for making dinner, since the logic of the buy...
Read more >Should I test inherited methods?
Even if the method is not overridden, it might behave differently: ... Yes, you should test inherited methods because in the future they...
Read more >Three Reasons Why We Should Not Use Inheritance In Our ...
If we use inheritance in our tests, it can have a negative effect to the performance of our test suite. In order to...
Read more >Group Permission Inheritance not working as intended - GitLab
Sub-members of groups are not getting the proper inheritance when using the invite group method. ... What is the expected correct behavior?
Read more >Ethical issues in predictive genetic testing: a public ... - NCBI
Reasons for not billing their insurance company included fear of genetic ... It would be expected that most mandatory testing would be provided...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
More than a year later and this still does not work. @cbeust IMHO this does not make any sense: since the parent class is abstract, its group resolution should be based in a concrete instance of a test class.
BTW, my solution is to use excludedgroups which of course won’t work in all situations. @cbeust, has there been any work on a proper solution for this?