[英]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.在 IntelliJ 中,使用 JUnit 5 的 Springboot 项目 (2.6.6),给定以下测试 class,IntelliJ不显示@BeforeAll 方法中发生的异常。
@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);
}
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.当@BeforeAll 方法比较复杂时,很难理解发生了异常,直到你偶然运行了整个测试 package。
In JUnit 4 with a @Before method, IntelliJ was showing test failure, with the stacktrace of the exception (which makes things easier to debug).在 JUnit 4 中,使用 @Before 方法,IntelliJ 显示测试失败,并显示异常堆栈跟踪(这使得调试更容易)。
My pom.xml only dependencies are spring-boot-starter & spring-boot-starter-test.我的 pom.xml 唯一的依赖项是 spring-boot-starter & spring-boot-starter-test。
Is this a bug / Is there any solution to reproduce the old behaviour?这是一个错误/是否有重现旧行为的解决方案?
Stack:堆:
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.正如评论中所指出的,要重现@Before
的 @Before,您应该在 Junit 5 中使用@BeforeEach
。在这种情况下,即使仅运行给定的测试 class,IntelliJ 也会像以前一样运行并显示异常。
For the @BeforeAll
, question is still pending.对于@BeforeAll
,问题仍然悬而未决。
A bug has been opened for the @BeforeAll
exceptions: https://youtrack.jetbrains.com/issue/IDEA-292662已为@BeforeAll
异常打开一个错误: https://youtrack.jetbrains.com/issue/IDEA-292662
Bug resolved in IntelliJ 2022.1.1 Preview.错误已在 IntelliJ 2022.1.1 预览版中解决。
See YouTrack: IDEA-292662请参阅 YouTrack: IDEA-292662
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.