question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inherited test methods do not get expected group behavior

See original GitHub issue

Consider 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:closed
  • Created 12 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Controlixcommented, Jul 15, 2014

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.

1reaction
mumrahcommented, Jun 21, 2013

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found