Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KotlinTest NoClassDefFoundError #492

Open
davidsowerby opened this issue Oct 14, 2018 · 6 comments
Open

KotlinTest NoClassDefFoundError #492

davidsowerby opened this issue Oct 14, 2018 · 6 comments

Comments

@davidsowerby
Copy link

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")
    }
    
}
@cbeust
Copy link
Owner

cbeust commented Oct 14, 2018

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

@davidsowerby
Copy link
Author

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

@davidsowerby
Copy link
Author

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'.

@cbeust
Copy link
Owner

cbeust commented Oct 15, 2018

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
Copy link
Owner

cbeust commented Oct 15, 2018

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.

@davidsowerby
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants