mavn 执行 junit 单元测试的结果为 Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- surefire:3.2.5:test (default-test) @ joyupx-trade ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.609 s
[INFO] Finished at: 2024-08-20T11:14:32+08:00
[INFO] ------------------------------------------------------------------------
核心提示:
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
原因:一个测试用例都没有执行,所以失败 0 个,错误 0 个,跳过 0 个。
这多半是版本不一致导致。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<artifactId>mockito-junit-jupiter</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</exclusion>
</exclusions>
</dependency>
排除掉 Spring boot 自动引入的 junit 5 依赖,然后使用自己显示指定的版本或者直接使用 Spring boot 自动引入的版本。