Spring Boot 2.2 出现错误“带有 ID 'junit-vintage' 的 TestEngine 无法发现测试”

新手上路,请多包涵

我有一个使用 Spring Boot 和 Junit 5 的简单应用程序:

  • 使用 Spring Boot 2.1(例如,2.1.8 或 2.1.12)时,我的单元测试运行顺利

  • 使用 Spring Boot 2.2(例如,2.2.2.RELEASE 或 2.3.2.RELEASE)时,我的单元测试失败并显示错误消息

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project XXX: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Projets\workspace\XXX\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:656)

我正在使用 Maven 3.6.1、JDK 1.8、JUnit 5.6.0 和 JUnit 平台 1.6.0。我从 spring-boot-starter-test 中排除了对 junit:junit 的依赖,因此依赖树中没有 JUnit 4 工件。请注意,Spring Boot 2.2 和 2.3 都使用 maven-surefire-plugin ,所以我的问题并非源于 maven-surefire-plugin 的任何回归。

我应该坚持使用 Spring Boot 2.1 以使我的单元测试正常工作吗?

在此先感谢您的帮助。

原文由 Ivan dal Bosco 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
1 个回答

我发现了错误。对 spring-boot-starter-test 的依赖带来了对 junit-vintage-engine 的依赖。后者必须排除:

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

原文由 Ivan dal Bosco 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进