首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ID为“junit-vintage”的TestEngine未能发现测试- JUnitException:未能解析junit:junit: 4.13.2

ID为“junit-vintage”的TestEngine未能发现测试- JUnitException:未能解析junit:junit: 4.13.2
EN

Stack Overflow用户
提问于 2021-05-17 04:03:48
回答 3查看 17.7K关注 0票数 10

我的Gradle配置和JUnit有一个非常奇怪的问题,我尝试更新到5.7+,但是我得到了以下例外:

代码语言:javascript
复制
org/junit/jupiter/api/extension/ScriptEvaluationException
java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException

顺便说一下,我的分级版本是6.8.3。另一方面,这里是我在下面的当前配置中得到的一个例外,我尝试了很多版本和库的组合,但是它们似乎都不起作用:

代码语言:javascript
复制
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$000(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)
代码语言:javascript
复制
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()
}

有人知道怎么做吗?

谢谢你的帮助。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-05-17 08:46:34

由于JUnit中有一个bug,junit-vintage-engine:5.6.2不支持JUnit 4.13.2。它只支持4.124.13。所以你才会看到这个例外。

这个bug是在JUnit 5.6.3中修复的。详情请参见https://github.com/junit-team/junit5/issues/2198

您还混合了JUnit 5工件的版本,您应该尽量避免这种情况。例如,如果您想使用JUnit平台1.7.2,我建议您使用JUnit木星5.7.2和JUnit Vintage 5.7.2。

有关如何使用Spring正确配置JUnit版本的详细信息,请参阅第5级JUnit BOM和Spring错误版本

票数 23
EN

Stack Overflow用户

发布于 2021-08-19 19:37:30

我也犯了这个错误。在我的idea项目文件中,我声明了两个版本的junit依赖项,分别为5.4.2和4.13.2。摆脱4.13.2为我解决了这个问题。

票数 0
EN

Stack Overflow用户

发布于 2022-05-04 12:29:47

我通过添加spring文档中建议的依赖来解决这个问题:

代码语言:javascript
复制
<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>
</dependency>

参考文档:弹簧-启动7.8 -测试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67563862

复制
相关文章

相似问题

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