【发布时间】:2021-07-03 18:07:19
【问题描述】:
我正在使用 BOM 开发一个非常简单的 Spring Boot 2.4.2 项目:
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
当运行mvn clean verify 时,我明白了:我们看到 Surefire 2.12.4 没有找到任何测试
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ api-testing ---
[INFO] Surefire report directory: C:\Users\vincent\IdeaProjects\api-testing\target\surefire-reports
------------------------------------------------------- T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我不明白为什么.. 我尝试了几件事,即使不推荐,我也尝试通过在我的 pom 中添加这个来覆盖版本:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
现在我的测试找到了!
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ api-testing ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running de.vincent.AssetReferentialServiceTest
我对 Spring Boot 的这种行为感到非常惊讶 - 我认为我遗漏了一些东西.. 但是什么?
注意:我的测试是 Junit 5 测试,我的类路径中没有与 Junit 4 相关的 jar - 只有 Junit Jupiter 5.7.0 和 Junit platform 1.7.0
谢谢
【问题讨论】:
-
为什么还要使用那个版本的插件? Spring Boot 已经使用更新版本来兼容 JUnit5。因此,要么您使用的是旧版本的 maven,它使用了该插件的旧版本,要么您已经在某处覆盖了它。啊主要问题是您正在导入 bom 而不是使用 Spring Boot 作为父级(因此它不会为插件设置版本,它将使用超级 pom 中的 maven 指定的默认版本)。跨度>
标签: spring-boot maven-surefire-plugin