1

我在 Spring Boot 项目中使用kotlintest进行单元和集成测试。我可以在 IntelliJ 中毫无问题地运行我的单元测试,并且它们都是绿色的。但是,当我在 gradle 中运行我的测试时./gradlew clean test,我所有使用table(),headers()row()函数的测试都失败了,但出现以下异常:

java.lang.NoClassDefFoundError: io/kotlintest/tables/TableTestingKt
    at com.tractive.hwservice.MessageContentExtensionsSpec$7.invokeSuspend(MessageContentExtensionsSpec.kt:110)
    at com.tractive.hwservice.MessageContentExtensionsSpec$7.invoke(MessageContentExtensionsSpec.kt)
    at io.kotlintest.runner.jvm.TestCaseExecutor$executeTest$supervisorJob$1$invokeSuspend$$inlined$map$lambda$1.invokeSuspend(TestCaseExecutor.kt:130)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ClassNotFoundException: io.kotlintest.tables.TableTestingKt
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    ... 8 more

所有其他测试都很好。

这是我的一部分build.gradle

repositories {
    mavenCentral()
}

dependencyManagement {
    dependencies {
        dependency 'ch.qos.logback.contrib:logback-classic:1.1.7'
        dependency 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
        dependency 'ch.qos.logback.contrib:logback-jackson:0.1.5'
        dependency 'com.fasterxml.jackson.core:jackson-databind:2.9.3'
        dependency 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.7'
        dependency 'org.assertj:assertj-core:3.9.1'
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-amqp'
    implementation 'org.springframework.boot:spring-boot-starter-integration'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'

    compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'com.fasterxml.jackson.core:jackson-databind'
    compile 'ch.qos.logback.contrib:logback-jackson'
    compile 'ch.qos.logback.contrib:logback-json-classic'
    compile 'com.fasterxml.jackson.module:jackson-module-kotlin'

    testCompile 'org.assertj:assertj-core'
    testCompile 'org.junit.jupiter:junit-jupiter-api'
    testCompile 'org.junit.jupiter:junit-jupiter-params'
    testCompile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'

    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.amqp:spring-rabbit-test'
    testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.3'
    testImplementation 'io.kotlintest:kotlintest-extensions-spring:3.3.3'
    testImplementation 'io.kotlintest:kotlintest-assertions:3.3.3'

}

jacocoTestReport {
    reports {
        xml.enabled true
    }
}

test {
    useJUnitPlatform ()
    finalizedBy jacocoTestReport
}

根据我的阅读,我什至不需要io.kotlintest:kotlintest-assertions依赖项,因为它应该包含在跑步者中。

看起来 TableTestingKt 没有像它应该的那样转换为一个类。

4

1 回答 1

0

这一切都归结为错误的 Java 版本 - 我在 IntelliJs 设置中设置了 Java 11,但我的 JavaHome 指向导致此错误的 Java 10。

于 2019-10-23T14:25:36.850 回答