英文:
No tests were found - when using JUnit5 [in IntelliJ IDEA]
问题
使用Java 11和JUnit 5堆栈的项目在IntelliJ IDEA中一直输出"未找到测试",如果运行测试(因此,如果尝试通过maven的surefire插件mvn test
运行测试,则不运行任何测试)。
我尝试了许多变化,最后找到了解决方案。如果pom.xml
包含以下内容:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version> <!--我认为这是问题的关键入口-->
</parent>
那么测试将不会运行,而IntelliJ将始终打印"未找到测试";但是,如果我简单地从pom.xml
中删除<parent/>
元素或将其版本更改为2.3.0.RELEASE
,则立即解决此问题。
好了,问题就是这样解决的,似乎是某个插件或传递性依赖项的问题;不过,有关与JUnit5引擎究竟不匹配的任何想法吗?
英文:
Project, with Java 11 and JUnit 5 stack, keeps outputting "No tests were found" in IntelliJ IDEA, if running tests (accordingly, not running any test if tried via maven's surefire plugin mvn test
).
I've tried many variations, and finally figured out the solution. If the pom.xml
has
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version> //I suppose this is important entry in this problem
</parent>
then tests won't run and instead IntelliJ would always print "No tests were found"; however, this is immediately resolved if I simply remove <parent/>
element from the pom.xml
or change its version to 2.3.0.RELEASE
OK, the problem is solved like that, and it seems like some plugin or transitive dependency problem; however, any ideas what exactly mismatches with JUnit5 engine?
答案1
得分: 2
在你的JAVA测试文件中,请确保导入org.junit.jupiter.api.Test;
而不是org.junit.Test;
。
英文:
In your JAVA test file, make sure you import org.junit.jupiter.api.Test;
and not import org.junit.Test;
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论