Intellij未显示@beforeall Junit5的例外5
在Intellij中,使用Junit 5的Springboot项目(2.6.6),给定以下测试类,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);
}
在Intellij(仅此类)中运行该类
运行test
当@beforeall方法更为复杂时,很难理解发生了一个例外,直到您偶然运行整个测试包。
在使用@Before方法的Junit 4中,Intellij显示了测试失败,并具有异常的基础(这使得更容易调试)。
我的pom.xml只有依赖项是弹簧启动starter&弹簧启动测试。
这是一个错误 /是否有任何解决方案可以重现旧行为?< / strong>
堆栈:
- Spring Boot 2.6.6 / junit 5
- Intellij Ideas 2022.1构建#iu-221.5080.210
- OpenJDK_X64TEMURIN_11.11.11.14.14.1_1 / MAVEN--14.1 / MAVEN--- 3.8.4
编辑
评论中指出的 ,要重现Junit4的 @before ,您应该在Junit 5中使用@beforeeach
。在这种情况下,Intellij将像以前一样行事即使仅运行给定的测试类,也会显示异常。
对于@beforeall
,问题仍在待处理。
编辑2
为@beforeall
例外打开了一个错误: https:> https: //youtrack.jetbrains.com/issue/idea-292662
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Intellij 2022.1.1预览中解决了错误。
请参阅youtrack: IDEA-292662
Bug resolved in IntelliJ 2022.1.1 Preview.
See YouTrack: IDEA-292662