Multiplatform: Running kotlin.test Common tests and io.kotlintest JVM tests

I have some tests in my commonTest directory that use the built-in kotlin.test library, and some other tests in jvmTest that use io.kotlintest. I start out with a fairly vanilla build.gradle file.

If I run the jvmTest task, it executes my commonTest tests but not my jvmTest tests.

If I go back and add jvmTest.useJUnitPlatform() to my build.gradle, then run jvmTest again, it executes my jvmTest tests, but not my commonTest tests.

Basically it looks like there’s no way to configure build.gradle such that my commonTest and jvmTests run in the same execution.

Thoughts?

To make it work you need to make the jvmTest sourceSet depend on the commonTest sourceSet. In addition you will need to add the junit implementation to the dependencies for jvmTest (the same is true for any other platform you may want to run the common tests on). Some example of how I’ve implemented it is here:

Thanks…I tried adding dependsOn commonTest to my jvmTest.dependencies block, but unfortunately this seemed not to work for me. The junit implementation was already present in jvmTest:

jvmTest {
    dependencies {
        dependsOn commonTest
        implementation kotlin('test')
        implementation kotlin('test-junit5')
        implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
    }
}

Alright, this works for me:

jvmTest {
    dependencies {
        implementation kotlin('test')
        implementation kotlin('test-junit5')
        implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
        runtimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
    }
}

Seems it wasn’t working because there was no (junit) TestEngine to pick up the commonTest-style tests. Not sure how that was ever working, even before kotlintest. Anyway, this works :slight_smile: