Maven 未运行 JUnit 测试

rit*_*att 3 java junit maven maven-surefire-plugin

我的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>
Run Code Online (Sandbox Code Playgroud)

但当我这样做时mvn clean test

-------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)

请注意,IntelliJ 确实可以识别测试 在此输入图像描述 (尽管当我单击test文件夹并选择时Run All Tests,它会说No tests found

为什么 Maven 不运行我的单元测试以及如何修复它?

ams*_*ger 6

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