@BeforeClass of superclass is not executed
See original GitHub issueContrary to the statement in @BeforeClass
annotation javadoc :
/** The @BeforeClass methods of superclasses will be run before those the current class. */
The @BeforeClass
annotated method of superclass is not called if there is another @BeforeClass
is subclass.
public abstract class SuperTest {
@BeforeClass
public static void beforeClass() throws Exception {
fail("why don't you call me ?"); // never fails
}
}
public class MyTestA extends SuperTest {
@BeforeClass
public static void beforeClass() {
fail("Thanks for calling"); // fails here
}
@Test
public void test() {
fail("Failure expected from MyTestA.beforeClass()");
}
}
public class MyTestB extends SuperTest {
@BeforeClass
public static void beforeClass() {
}
@Test
public void test() {
fail("Failure expected from SuperTest.beforeClass()"); // fails here
}
}
Issue Analytics
- State:
- Created 12 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
TestNG @BeforeClass doesn't run from super class if it not an ...
I have @BeforeClass testng annotation in class A. And I only annotate class C with @Test. Now, I expect that while running class...
Read more >AfterClass (JUnit API)
The @AfterClass methods declared in superclasses will be run after those of the current class, unless they are shadowed in the current class....
Read more >Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
When we want to execute an expensive common operation before each test, it's preferable to execute it only once before running all tests...
Read more >Common test superclass, @BeforeClass fails for one test, and ...
Hi Cedril, I have a test hierarchy: public class AbstractTest { @BeforeClass public void beforeAbstractTestClass() { System.out.println("<<<<<>>>>>
Read more >JUnit Test Cases @Before @BeforeClass Annotation - Guru99
JUnit does not require server for testing web application, which makes the testing ... Execute the JUnit @Before methods in the superclass ......
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
The method in the superclass is shadowed by the method with the same name in the subclass. If you give the @BeforeClass methods different names, they will run in the correct order.
thanks taral, issue is settled then. A little mention in the javadoc of @BeforeClass could be helpful though.