kobalt icon indicating copy to clipboard operation
kobalt copied to clipboard

KotlinTest NoClassDefFoundError

Open davidsowerby opened this issue 7 years ago • 6 comments
trafficstars

Attempting to run tests with KotlinTest causes the error below. I think it is simply because the Kobalt KotlinTestRunner is based on JUnit4. KotlinTest uses JUnit5, from version 3.0.0 I believe, which would have been after you added KotlinTest support at #312

───── kayman-design:compile ───── kayman-design:compileTest ───── kayman-design:test Running tests with JUnit 4


***** ERROR Error: java.lang.NoClassDefFoundError: io/kotlintest/specs/BehaviorSpec


import com.beust.kobalt.project
import com.beust.kobalt.test

val p = project {
    name = "kayman-design"
    group = "com.example"
    artifactId = name
    version = "0.1"

    dependencies {
        compile("org.jetbrains.kotlin:kotlin-runtime:1.2.61")
        compile("org.jetbrains.kotlin:kotlin-stdlib:1.2.61")
    }

    dependenciesTest {
        compile("io.mockk:mockk:1.8.6")
        compile("io.kotlintest:kotlintest-runner-junit5:3.1.10")
    }
    
}

davidsowerby avatar Oct 14 '18 10:10 davidsowerby

Can you attach your project, or link to it, so I can reproduce this?

cbeust avatar Oct 14 '18 12:10 cbeust

I'll put up a sample project - give me a day or so ...

davidsowerby avatar Oct 14 '18 18:10 davidsowerby

I've put up a sample project which seems to confirm my suspicion that it is a runner change that is needed.

I also noticed that when the test run fails under these conditions, the build is still reported as successful:

 ╔════════════════════════════╗
 ║ Building kobalt-kotlintest ║
 ╚════════════════════════════╝

───── kobalt-kotlintest:compile ───── kobalt-kotlintest:compileTest ───── kobalt-kotlintest:test Running tests with JUnit 4


***** ERROR Error: java.lang.NoClassDefFoundError: io/kotlintest/specs/BehaviorSpec


Thread report ╔════════════════════════════════════════╗ ║ Time (sec) ║ Thread 12 ║ ╠════════════════════════════════════════╣ ║ 0 ║ kobalt-kotlintest ║ ╚════════════════════════════════════════╝ ╔═════════════════════════════════════════════════════════╗ ║ Project ║ Build status║ Time ║ ╠═════════════════════════════════════════════════════════╣ ╚═════════════════════════════════════════════════════════╝ PARALLEL BUILD SUCCESSFUL (0 SECONDS), sequential build would have taken 0 seconds 10:12:35: Task execution finished 'test'.

davidsowerby avatar Oct 15 '18 09:10 davidsowerby

There was a bug in how Kobalt detects whit JUnit runner to use (it mistakenly used JUnit 4).

With 1.0.117, JUnit 5 is correctly detected on your project, however, I'm now getting different errors after that. I suspect the way to invoke and build JUnit 5 tests has slightly changed since last time I wrote this code.

Do you have a Gradle build that works on your tests, something I could compare with?

cbeust avatar Oct 15 '18 21:10 cbeust

In the meantime, you can run ./kobaltw --update to update to 117 and try again. You'll see a lot of warnings during discovery and finally a compilation error.

cbeust avatar Oct 15 '18 21:10 cbeust

That was quick. I can see the warnings and the compile error in Build.kt. I've put up a Gradle equivalent, but limited both the Gradle and Kobalt builds to KotlinTest3 - just makes things easier. Let me know if you need KotlinTest2

I've also added a failing test to both, and used KotlinTest's in-built assertions as a more realistic scenario. Interestingly these caused a compile error, because the test is still using the KotlinTest 2.0.7 library.

Knowing this sometimes happens in IDEA, I tried re-importing - but that refused to work because of the compile error.

davidsowerby avatar Oct 16 '18 08:10 davidsowerby