No tests were found – when using JUnit5 [in IntelliJ IDEA]

huangapple go评论75阅读模式
英文:

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

&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.2.1.RELEASE&lt;/version&gt; //I suppose this is important entry in this problem
&lt;/parent&gt;

then tests won't run and instead IntelliJ would always print "No tests were found"; however, this is immediately resolved if I simply remove &lt;parent/&gt; 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;.

huangapple
  • 本文由 发表于 2020年8月11日 00:19:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63344030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定