Execute unit test in native platform ios


#1

Hi,
I’m currently trying the new mpp model in 1.3. I’ve created an iOS Android app. And now I want to unit test the common module. Running some example tests I’ve realized that tests only runs on JVM. Can I execute them on iOS app aswell ?


#2

Hi, a similar question was asked in Kotlin Slack recently. To run tests on ios you can use a task like this one:

task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.compilations.test.getBinary('EXECUTABLE', 'DEBUG')
        exec {
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}