【问题标题】:Maven not running JUnit testMaven 没有运行 JUnit 测试
【发布时间】:2021-12-16 10:51:35
【问题描述】:

我的pom.xml

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.8.1</version>
  <scope>test</scope>
</dependency>
...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M5</version>
</plugin>

但是当我这样做时mvn clean test

-------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

请注意,IntelliJ 确实可以识别测试 (虽然当我单击test 文件夹并选择Run All Tests 时,它会显示No tests found

为什么 Maven 不运行我的单元测试,我该如何解决?

【问题讨论】:

  • 你是否使用了正确的注解org.junit.jupiter.api.Test
  • (它将显示为测试文件顶部的import 语句之一)
  • 你能展示包括导入在内的整个测试类吗?
  • @amseager 不,我不是。解决了这个问题。请随时将其发布为答案,或者我可以为您做。谢谢!

标签: java maven junit maven-surefire-plugin


【解决方案1】:

如果您使用的是 JUnit 5 (Jupiter),则需要导入 org.junit.jupiter.api.Test 而不是 org.junit.Test(后者适用于 JUnit 4)。

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 2013-08-23
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    相关资源
    最近更新 更多