使用 JDK 17 的 Spring Boot 2.5+ - maven Surefire 不执行现有测试

tm1*_*701 0 maven maven-surefire-plugin spring-boot

使用 JDK 17 将 Spring Boot 2.2 应用程序更改为 2.5.5 时,Surefire 测试插件不会启动任何现有测试。这是消息:

[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)

为什么它不启动任何现有的测试?测试的名称是*Test.java。

当显式添加版本高于 2.19 的 Surefire 插件时,我看到了类似的行为。Spring Boot 测试启动器将有一个更新的 Surefire 插件。

Maven版本是3.6.3。路径上是jdk17.1.0。

<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)

我查看了类似的问题,发现测试文件夹的路径应该位于“src”下方。是的。

在此输入图像描述

在文件夹中是相同的:

在此输入图像描述

这两个文件夹下面都是一个“java”文件夹。

Surefire 没有明确地出现在 pom.xml 中,因为它位于 spring-boot-test 启动器中。

sou*_*ung 7

您的项目中存在什么样的测试?集成测试或/和单元测试?您能提供更多有关您的背景的详细信息吗?

\n

不管怎样,从 spring-boot 2.4.0 版本开始,JUnit 5\xe2\x80\x99s Vintage Engine 被移除了spring-boot-starter-test.

\n

据说在2.4.0发行说明页面https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes

\n
\n

如果您升级到 Spring Boot 2.4 并看到 JUnit 类的测试编译错误,例如org.junit.Test,这可能是因为 JUnit 5\xe2\x80\x99s 老式引擎已从spring-boot-starter-test。vintage 引擎允许使用 JUnit 4 编写的测试由 JUnit 5 运行。如果您不想将测试迁移到 JUnit 5 并且希望继续使用 JUnit 4,请添加对 Vintage 引擎的依赖项,如以下示例所示对于 Maven:

\n
\n
<dependency>\n    <groupId>org.junit.vintage</groupId>\n    <artifactId>junit-vintage-engine</artifactId>\n    <scope>test</scope>\n    <exclusions>\n        <exclusion>\n            <groupId>org.hamcrest</groupId>\n            <artifactId>hamcrest-core</artifactId>\n        </exclusion>\n    </exclusions>\n</dependency>\n
Run Code Online (Sandbox Code Playgroud)\n