-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed as not planned
Closed as not planned
Copy link
Description
After upgrading to JUnit 5.11, if a testbase class has a static method with the @BeforeAll annotation and its inherited testbase class also has the static method (with the same method name as its parent class) with the @BeforeAll annotation, both of the static methods with the @BeforeAll annotation are called. However, in Junit 5.10, only the 2nd static method with @BeforeAll is called.
I would like to ask if it's intended, and if it's intended, is there any way to suppress calling the first static method with the @BeforeAll annotation?
Steps to reproduce
Assuming the following class structure, the actual tests are in the TestA class.
abstract class TestBase (including @BeforeAll)
<- abstract class Feature1TestBase (including @BeforeAll)
<- class TestA
When you run the tests in TestA,
- In JUnit 5.11.1, a static method with
@BeforeAllin theTestBaseclass is called, then the same name static method with@BeforeAllin theFeature1TestBaseclass is called. - In JUnit 5.10, only a static method with
@BeforeAllin theFeature1TestBaseclass is called, the static method in theTestBaseclass is NOT called.
The below shows more details:
Code
TestBase:
// TestBase
import org.junit.jupiter.api.BeforeAll;
public abstract class TestBase {
@BeforeAll
public static void beforeAll() {
System.out.println("Run beforeAll in TestBase.");
}
public void testMethod() {
System.out.println("Run testMethod in TestBase.");
}
}Feature1TestBase:
import org.junit.jupiter.api.BeforeAll;
public abstract class Feature1TestBase extends TestBase {
@BeforeAll
public static void beforeAll() {
System.out.println("Run beforeAll in Feature1TestBase.");
}
}TestA:
import org.junit.jupiter.api.Test;
public class TestA extends ConcreteTestBase {
@Test
public void runTestA1() {
testMethod();
}
}Output
JUnit 5.11.1:
Run beforeAll in TestBase.
Run beforeAll in Feature1TestBase.
Run testMethod in TestBase.JUnit 5.10.5:
Run beforeAll in Feature1TestBase.
Run testMethod in TestBase.
Context
- Used versions (Jupiter/Vintage/Platform): JUnit 5.11.1 and JUnit 5.10.5 (
org.junit.jupiter:junit-jupiter:5.11.1andorg.junit.jupiter:junit-jupiter:5.10.5) - Build Tool/IDE: IntelliJ IDEA 2024.1.4 (Ultimate Edition)
Deliverables
n/a