ID 为 'junit-vintage' 的 TestEngine 未能发现测试 - JUnitException:无法解析 junit:junit 的版本:4.13.2
TestEngine with ID 'junit-vintage' failed to discover tests - JUnitException: Failed to parse version of junit:junit: 4.13.2
我的 Gradle 配置和 JUnit 遇到了一个非常奇怪的问题,我尝试更新到 5.7+,但出现以下异常:
org/junit/jupiter/api/extension/ScriptEvaluationException
java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException
顺便说一句,我的Gradle版本是6.8.3。另一方面,这是我在下面的当前配置中遇到的异常,我尝试了很多版本和库的组合,但似乎 none 它们都有效:
Caused by: org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' 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.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access[=13=]0(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
... 25 more
Caused by: org.junit.platform.commons.JUnitException: Failed to parse version of junit:junit: 4.13.2
at org.junit.vintage.engine.JUnit4VersionCheck.parseVersion(JUnit4VersionCheck.java:54)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:37)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:32)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62)
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'com.palantir.docker' version '0.26.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
docker {
name "{project.name}"
dockerfile file('src/docker/Dockerfile')
copySpec.from( jar ).rename(".*", "crm_lead_validator.jar")
buildArgs( ['JAR_FILE':"crm_lead_validator.jar"] )
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.jeasy:easy-random-core:5.0.0'
implementation 'io.github.openfeign:feign-jackson:9.3.1'
implementation 'com.github.tomakehurst:wiremock:2.25.1'
implementation 'org.mock-server:mockserver-netty:3.10.8'
implementation 'org.mock-server:mockserver-client-java:3.10.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.3'
implementation 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
implementation 'io.github.openfeign:feign-okhttp:10.11'
implementation 'io.github.openfeign:feign-slf4j:10.11'
implementation 'io.github.openfeign:feign-gson:10.11'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
// https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
testImplementation "org.junit.vintage:junit-vintage-engine:5.6.2"
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.2'
}
test {
useJUnitPlatform()
}
有谁知道如何让它工作吗?
感谢您的帮助。
由于 JUnit 中的错误,junit-vintage-engine:5.6.2
不支持 JUnit 4.13.2
。它只支持 4.12
或 4.13
。这就是为什么您会看到该异常。
该错误已在 JUnit 5.6.3 中修复。有关详细信息,请参阅 https://github.com/junit-team/junit5/issues/2198。
您还混合了 JUnit 5 工件的版本,您应该尽量避免这种情况。例如,如果您想使用 JUnit Platform 1.7.2,我建议您使用 JUnit Jupiter 5.7.2 和 JUnit Vintage 5.7.2。
有关如何使用 Spring 引导正确配置 JUnit 版本的详细信息,请参阅
.
我也遇到了这个错误。
在我的想法项目文件中,我声明了 2 个版本的 junit 依赖项,5.4.2 和 4.13.2。
摆脱 4.13.2 为我解决了这个问题。
我按照 spring 文档的建议通过添加依赖项解决了这个问题:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
我的 Gradle 配置和 JUnit 遇到了一个非常奇怪的问题,我尝试更新到 5.7+,但出现以下异常:
org/junit/jupiter/api/extension/ScriptEvaluationException
java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException
顺便说一句,我的Gradle版本是6.8.3。另一方面,这是我在下面的当前配置中遇到的异常,我尝试了很多版本和库的组合,但似乎 none 它们都有效:
Caused by: org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' 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.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access[=13=]0(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
... 25 more
Caused by: org.junit.platform.commons.JUnitException: Failed to parse version of junit:junit: 4.13.2
at org.junit.vintage.engine.JUnit4VersionCheck.parseVersion(JUnit4VersionCheck.java:54)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:37)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:32)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62)
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'com.palantir.docker' version '0.26.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
docker {
name "{project.name}"
dockerfile file('src/docker/Dockerfile')
copySpec.from( jar ).rename(".*", "crm_lead_validator.jar")
buildArgs( ['JAR_FILE':"crm_lead_validator.jar"] )
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.jeasy:easy-random-core:5.0.0'
implementation 'io.github.openfeign:feign-jackson:9.3.1'
implementation 'com.github.tomakehurst:wiremock:2.25.1'
implementation 'org.mock-server:mockserver-netty:3.10.8'
implementation 'org.mock-server:mockserver-client-java:3.10.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.3'
implementation 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
implementation 'io.github.openfeign:feign-okhttp:10.11'
implementation 'io.github.openfeign:feign-slf4j:10.11'
implementation 'io.github.openfeign:feign-gson:10.11'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
// https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
testImplementation "org.junit.vintage:junit-vintage-engine:5.6.2"
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.2'
}
test {
useJUnitPlatform()
}
有谁知道如何让它工作吗?
感谢您的帮助。
由于 JUnit 中的错误,junit-vintage-engine:5.6.2
不支持 JUnit 4.13.2
。它只支持 4.12
或 4.13
。这就是为什么您会看到该异常。
该错误已在 JUnit 5.6.3 中修复。有关详细信息,请参阅 https://github.com/junit-team/junit5/issues/2198。
您还混合了 JUnit 5 工件的版本,您应该尽量避免这种情况。例如,如果您想使用 JUnit Platform 1.7.2,我建议您使用 JUnit Jupiter 5.7.2 和 JUnit Vintage 5.7.2。
有关如何使用 Spring 引导正确配置 JUnit 版本的详细信息,请参阅
我也遇到了这个错误。 在我的想法项目文件中,我声明了 2 个版本的 junit 依赖项,5.4.2 和 4.13.2。 摆脱 4.13.2 为我解决了这个问题。
我按照 spring 文档的建议通过添加依赖项解决了这个问题:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>