我正在从事一个对我来说很新但已经存在一段时间的项目。
我尝试使用 mvn clean test
从终端运行单元测试,单元测试按预期运行。
对我来说不幸的是,我真的可以在这些单元测试中使用 IntelliJ 的一些调试帮助。每当我尝试从 IntelliJ 运行单元测试时,我都会得到以下输出:
Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests
Caused by: org.junit.platform.commons.JUnitException: Unsupported version of junit:junit: 3.8.1. Please upgrade to version 4.12 or later.
根据 pom.xml,我使用的是 JUnit 5.7.0、Mockito 3.7.7,并且(因为我用谷歌搜索的一些结果表明它可能是 Spring Boot 问题)没有 Spring Boot 的迹象。我也尝试过包括 junit-vintage,因为它在输出中被提及,但这似乎也没有什么区别。
最佳答案
这是古老的 StackOverflow 诅咒——花上好几个小时寻找解决方案,却一无所获;在 StackOverflow 上发帖,即使有帮助的人也不知道问题出在哪里,但现在我可以从 Google 快速找到答案。
尽管我之前已将 junit-vintage 添加到我的项目中,但显然我没有添加正确的工件、版本或其他东西。因为这就是这里的解决方案。
Here is a link到导致我得到答案的讨论——添加这个依赖项:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
关于java - JUnit 通过命令行没问题,在 IntelliJ 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66055656/