'IntellIj not displaying exceptions from @BeforeAll JUnit5
In IntelliJ, with a Springboot project (2.6.6) using JUnit 5, given the following test class, IntelliJ doesn't display exceptions occuring in the @BeforeAll method.
@ExtendWith(SpringExtension.class)
public class SpringTest {
private Object OBJECT = new Object();
@BeforeAll
public static void before() {
throw new RuntimeException("SpringTest.RuntimeException"); // replace by actual business code
}
@Test
public void test() {
// Doesn't matter
assertNotNull(this.OBJECT);
}
Running the class within IntelliJ (only this class)
Running the package of the test
When the @BeforeAll method is more complex, it's hard to understand that an exception occured, until you run the whole test package by chance.
In JUnit 4 with a @Before method, IntelliJ was showing test failure, with the stacktrace of the exception (which makes things easier to debug).
My pom.xml only dependencies are spring-boot-starter & spring-boot-starter-test.
Is this a bug / Is there any solution to reproduce the old behaviour ?
Stack:
- Spring boot 2.6.6 / JUnit 5
- IntelliJ IDEA 2022.1 Build #IU-221.5080.210
- OpenJDK_x64Temurin_11.0.14.1_1 / Maven-3.8.4
Edit
As pointed out in the comment, to reproduce @Before
of JUnit4, you should use @BeforeEach
in Junit 5. In this case, IntelliJ will behave as before and display exceptions even when running only the given test class.
For the @BeforeAll
, question is still pending.
Edit 2
A bug has been opened for the @BeforeAll
exceptions: https://youtrack.jetbrains.com/issue/IDEA-292662
Solution 1:[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bapt_ |