首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SpringBoot2.2错误“ID为'junit-vintage‘的TestEngine未能发现测试”

使用SpringBoot2.2错误“ID为'junit-vintage‘的TestEngine未能发现测试”
EN

Stack Overflow用户
提问于 2020-01-24 16:47:41
回答 20查看 149.1K关注 0票数 98

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

  • 当使用Spring 2.1 (例如,2.1.8或2.1.12)时,我的单元测试运行平稳
  • 当使用SpringBoot2.2(例如,2.2.2.RELEASE或2.3.2.RELEASE)时,我的单元测试失败并出现错误消息
代码语言:javascript
复制
[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、JDK1.8、JUnit 5.6.0和JUnit平台1.6.0。我从junit:junit中排除了对spring-boot-starter-test的依赖,这样在依赖树中就没有JUnit 4工件了。请注意,SpringBoot2.2和2.3都使用了maven-surefire-plugin 2.22.2,所以我的问题并不源于maven-surefire-plugin的任何回归。

为了让我的单元测试工作,我应该坚持使用Spring 2.1吗?

提前谢谢你的帮助。

EN

回答 20

Stack Overflow用户

发布于 2020-02-28 10:55:22

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

代码语言:javascript
复制
<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>
票数 118
EN

Stack Overflow用户

发布于 2020-10-17 14:07:51

显式地添加以下依赖项以升级junit-vintage-engine解决了这个问题:

代码语言:javascript
复制
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.7.0</version>
</dependency>
票数 44
EN

Stack Overflow用户

发布于 2021-08-28 07:19:45

最好的选择是在启用调试的情况下运行Maven测试:

例如mvn clean test -X。它将显示出确切的失败原因。

在我的例子中,我试图运行一些Spock测试,但是找不到所需的Groovy依赖项(请参阅下面的堆栈跟踪)。当我显式地添加Groovy依赖项时,就解决了这个问题。

代码语言:javascript
复制
TestEngine with ID 'spock' failed to discover tests
org.junit.platform.commons.JUnitException: TestEngine with ID 'spock' failed to discover tests
        at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:111)
        at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:85)
        at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:92)
        at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:67)
        at org.apache.maven.surefire.junitplatform.TestPlanScannerFilter.accept(TestPlanScannerFilter.java:56)
        at org.apache.maven.surefire.api.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.scanClasspath(JUnitPlatformProvider.java:147)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:128)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
Caused by: java.lang.NoClassDefFoundError: groovy/xml/MarkupBuilder
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
...
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59900637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档