https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Alexander Larsson

06/09/2020, 2:36 PM
What is the best practice for testing common code on Android? In my Kotlin MPP the
allTests
task runs tests only on iOS (specifically a task called
iosSimTest
). If you write Android specific tests they run on android successfully by running the task called
testDebugUnitTest
. I cannot figure out how to run the common test cases on Android. Am I supposed to run them on JVM and it is not possible to run on Android? I currently do not have a JVM target set up since it is an iOS/Android project only.
I set up a JVM target to run the Android tests with like this:
Copy code
val jvmTest by getting {
    dependencies {
        implementation(kotlin("test"))
        implementation(kotlin("test-junit"))
    }
    kotlin.srcDir("src/androidTest/kotlin")
    resources.srcDir("src/androidTest/resources")
}

val androidMain by getting {
    dependencies {
        implementation(kotlin("stdlib"))
        implementation("io.ktor:ktor-client-android:$ktorVersion")
        implementation("io.ktor:ktor-client-json-jvm:$ktorVersion")
        implementation("io.ktor:ktor-client-serialization-jvm:$ktorVersion")
        implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
    }
}
Is this the best I can do? Cannot figure out how to run them directly on an Android emulator like on iOS.
2 Views