First of all, let me start by saying thanks for opening up more possibilities when testing on Kotlin with such a modern library 馃憤
I've been having trouble introducing KotlinTest to a codebase that currently runs on Junit4, as many Android projects do due to the slow adoption of Junit5.

./gradlew test shows no problemsException in thread "main" java.lang.NoClassDefFoundError:
org/junit/platform/launcher/TestExecutionListener
...
Caused by: java.lang.ClassNotFoundException:
org.junit.platform.launcher.TestExecutionListener
I can see that the -junit5 flag is being passed by the IDE, this flag doesn't get passed when KotlinTest is not a dependency of the project.
Motivated by this podcast episode, I've simplified a project to almost nothing to give a Simple, Self-Contained, Correct, Compilable Example. It consists of basically these components:
// The useJUnitPlatform() in testOptions is not used
dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.3.0'
}
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
class KotlinTest : StringSpec({
"length should return size of string" {
"hello".length shouldBe 5
}
"startsWith should test for a prefix" {
"world" should startWith("wor")
}
})
Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 16, 2019
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.3
I'll be very grateful for any hint to get this setup up and running. I understand Junit4 is not the focus of this library but from what I understand it is supported in the current version.
Alternatively, if you can point to a strong reason to move away from Junit4 right away, I will also apreciate to know if there is a simple way of migrating to Junit5 without touching every test in the project. At the moment I just want to use KotlinTest for new tests and progressively adapt older tests.
Thanks for your time and commitment
Sebastian
I think this problem is not related to kotlintest library but this is a bug in android studio. I had similar issues even without this library. If you want run all test from android studio you can make your own Android JUnit run configuration with test kind all in package or all in directory.
No, it is related to kotlintest. It works well on KotlinTest 3.1.5
I checked this again, problem starts with KotlinTest 3.2.0
@code-schreiber Not exactly related to the issue, but
Alternatively, if you can point to a strong reason to move away from Junit4 right away, I will also apreciate to know if there is a simple way of migrating to Junit5 without touching every test in the project.
you should be able to run JUnit4 tests using JUnit5's vintage runner pretty easily:
test {
useJUnitPlatform()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.5.0"))
testImplementation("junit:junit:4.12")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
}
See the example here https://github.com/junit-team/junit5-samples/tree/master/junit5-migration-gradle
Works for me on testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.4.2'
Full setup
testImplementation 'org.junit.platform:junit-platform-commons:1.5.2'
testImplementation 'org.junit.platform:junit-platform-launcher:1.5.2'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.5.2'
testImplementation 'org.junit.platform:junit-platform-engine:1.5.2'
testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.4.2'
Same error here starting with 3.1.6 (3.1.5 is the last version that works). Tested with 3.1.6, 3.1.7, 3.1.8, 3.2.0 and 3.3.0.
Android Studio version 3.5.3.
Works for me on
testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.4.2'Full setup
testImplementation 'org.junit.platform:junit-platform-commons:1.5.2' testImplementation 'org.junit.platform:junit-platform-launcher:1.5.2' testImplementation 'org.junit.vintage:junit-vintage-engine:5.5.2' testImplementation 'org.junit.platform:junit-platform-engine:1.5.2' testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.4.2'
Nope, does not work. No tests found.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any solutions, or still an open issue?
I am facing same issue with 4.2.5