https://kotlinlang.org logo
Title
a

Ahmed Mourad

11/04/2020, 8:39 AM
Hi, I'm trying to use Kotest with Android Instrumented tests but I'm getting this error as soon as I run my tests:
Exception in thread "main" java.lang.ClassNotFoundException: io.kotest.engine.launcher.MainKt
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at com.intellij.rt.execution.CommandLineWrapper.loadMainClassWithCustomLoader(CommandLineWrapper.java:193)
	at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:48)
I'm using a
DescribeSpec
with no
@RunWith
annotations:
class SomeTests : DescribeSpec({ ... })
This's what my
build.gradle
looks like:
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"
apply plugin: "de.mannodermaus.android-junit5"
...

android {
    compileSdkVersion 30
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...
    }
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

...

    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "androidx.test:core:1.3.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
    androidTestImplementation 'io.kotest:kotest-runner-junit5:4.3.1'
    androidTestImplementation 'io.kotest:kotest-assertions-core:4.3.1'
    androidTestImplementation 'io.kotest:kotest-property:4.3.1'
    androidTestImplementation 'io.kotest:kotest-assertions-arrow:4.3.1'
}
and this's what my test configs look like:
The tests also don't allow me to pick a device, which would be expected from an instrumented test
a

alexfacciorusso

11/04/2020, 9:07 AM
Hi Ahmed, Unfortunately at the moment the Android support for Kotest is very experimental. I hope to find some time to fix it completely. In the meantime, you can have a look at the sample project here. We are stuck with a minSdkVersion of
26
because of some dependencies in Kotest not compiling on earlier versions, but that example works for now
😓 1