我有一个使用Spring和Junit 5的简单应用程序:
[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吗?
提前谢谢你的帮助。
发布于 2020-02-28 10:55:22
我发现了错误。对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>发布于 2020-10-17 14:07:51
显式地添加以下依赖项以升级junit-vintage-engine解决了这个问题:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>发布于 2021-08-28 07:19:45
最好的选择是在启用调试的情况下运行Maven测试:
例如mvn clean test -X。它将显示出确切的失败原因。
在我的例子中,我试图运行一些Spock测试,但是找不到所需的Groovy依赖项(请参阅下面的堆栈跟踪)。当我显式地添加Groovy依赖项时,就解决了这个问题。
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)
...https://stackoverflow.com/questions/59900637
复制相似问题