Private @Before* methods aren't called when defined in a base class
See original GitHub issueTestNG Version
6.14.3 and 7.0.0-beta3, Java 8 and 11
Actual behavior
Private @Before*
methods aren’t called when defined in a base class, but work when defined in the same class.
Expected behavior
Private @Before*
methods should be called, whether they were inherited or not
Is the issue reproductible on runner?
- Shell
- Maven
- Gradle
- Ant
- Eclipse
- IntelliJ
- NetBeans
Test case sample
Following test passes - calls @BeforeMethod
public class NoInheritanceTest {
boolean called = false;
@BeforeMethod
private void init() {
called = true;
}
@Test
public void testWorks() {
assertTrue(called, "Should have been set in @Before");
}
}
Following test fails - @BeforeMethod
is not called:
public class ChildTest extends BaseTest {
@Test
public void testFails() {
assertTrue(called, "Should have been set in @Before");
}
}
public class BaseTest {
boolean called = false;
@BeforeMethod
private void init() {
called = true;
}
}
Test case project: https://github.com/zhogov/testng-issue-2097
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
private method in inheritance in Java - Stack Overflow
Private allows only the class containing the member to access that member. Protected allows the member to be accessed within the class and...
Read more >The purpose of private methods and when to use them
Private methods are typically used when several methods need to do the exact same work as part of their responsibility (like notifying external ......
Read more >Inheritance - Learning the Java Language
A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited...
Read more >Private class features - JavaScript - MDN Web Docs
Private properties with the same name within different classes are entirely different and do not interoperate with each other. See them as external...
Read more >private(call) and internal(call) - Discussion - Swift Forums
A method declared private(call) would behave exactly the same as a private method in almost all circumstances, the one exception being when a...
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
Ah I see, those private methods I mentioned are just for methods in general.
Yeah you’re right, somewhere outside of there you’d need to also check if they’re TestNG annotated methods before showing the warning, good catch!
#473 has a similar title but looks a bit different.
@Proryanator At our side, only console warnings are possible but IDEs can manage a better display if they want to warn against this bad usage (ping @missedone @akozlova )