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

Grzegorz Gajewski

11/30/2023, 7:20 PM
What am I missing here? I want to have unit tests in commonTest, and instrumentation test with shared test between iOS and Android. I have 3 source trees
Copy code
applyDefaultHierarchyTemplate {
        withSourceSetTree(
            KotlinSourceSetTree.Companion.main,
            KotlinSourceSetTree.Companion.test,
            KotlinSourceSetTree.Companion.instrumentedTest
        )
    }
Adding instrumentation test like this:
Copy code
listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        val instrumentedTest by it.compilations.creating {
            associateWith(it.compilations.getByName("main"))
        }
    }
This creates
commonInstrumentation
source sets Then in sourceSets I’m setting the dependency for androidInstrumentedTest
Copy code
sourceSets {
        val commonInstrumentedTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidInstrumentedTest by getting  {
            dependencies {
                implementation("androidx.test:runner:1.5.2")
            }
            dependsOn(commonInstrumentedTest)
        }
}
When I try to run it I have “Nothing here” and
./gradlew alltest
doesn’t run it either. Looks like is
commonInstrumentedTest
and
iosInstrumentedTest
are not recognized as test sources.
For future reference. With additional config, I am able to run test from command line:
Copy code
iosSimulatorArm64 {
    val instrumentedTest by compilations.creating {
        associateWith(compilations.getByName("main"))
    }
    binaries.test("instrumented") {
        compilation = instrumentedTest
    }
    testRuns.create("instrumented") {
        setExecutionSourceFrom(binaries.getTest("instrumented", NativeBuildType.DEBUG))
    }
}
It still doesn’t work in IDE. Maybe connected to KTIJ-25662
3 Views