Gradle的表驱动测试:NoClassDefFoundError TableTestingKt



我在Spring Boot项目中使用kotlintest进行单元和集成测试。我可以在IntelliJ中运行我的单元测试而没有任何问题,而且所有的测试都是绿色的。不过,当我使用./gradlew clean test在gradle中运行测试时,所有使用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依赖项,因为它应该包含在runner中。

看起来TableTestingKt并没有像应该的那样转换为类

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

相关内容

  • 没有找到相关文章

最新更新