mercredi 23 octobre 2019

Table Driven Tests with Gradle: NoClassDefFoundError TableTestingKt

I use kotlintest in a Spring Boot Project for unit and integration testing. I can run my unit tests without any troubles in IntelliJ and all of them are green. When I run my tests in gradle with ./gradlew clean test though, all my tests using the table(), headers() and row() functions fail with the following exception:

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

All other tests are fine.

Here is part of my 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
}

From what I read I shouldn't even need the io.kotlintest:kotlintest-assertions dependency as it should be included in the runner, so I am not really sure why the TableTestingKt is not found, it is in the kotlintest-assertions jar file.

Aucun commentaire:

Enregistrer un commentaire