I'm having some trouble getting tests to run for i...
# kotlin-native
s
I'm having some trouble getting tests to run for iOS with the new multiplatform plugin. Can anyone point me in the right direction?
Copy code
apply plugin: 'com.android.library'
apply plugin: 'kotlin-multiplatform'

android {
    compileSdkVersion androidConfig.compileSdkVersion

    defaultConfig {
        minSdkVersion androidConfig.minSdkVersion
        targetSdkVersion androidConfig.targetSdkVersion
    }
}

dependencies {
    testImplementation deps.kotlin.test.jvm
    testImplementation deps.kotlin.test.jvm_annotations
}

kotlin {
    targets {
        fromPreset(presets.android, 'android')
        fromPreset(presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    
    sourceSets {
        commonMain {
            dependencies {
                implementation deps.kotlin.stdlib
                api project(':store')
            }
        }
        iosMain {
        }
        commonTest {
            dependencies {
                implementation deps.kotlin.test.common
                implementation deps.kotlin.test.common_annotations
                implementation project(':store-test')
            }
        }
    }
}
t
Does kmpp sample work for you? It should have some tests included.
s
I'm following the format they give, but the native tests don't run
This is in the iosTest source set:
Copy code
class IosTest {
    @Test fun iosTest() {
        assertTrue { false }
    }
}
./gradlew test
and the build passes. If I do that with a common or an Android test, the build fails because the jvm targets are working properly it seems
Tests in the sample library seem to work if I run
./gradlew macosX64Test
I don't see an equivalent method for the iosX64 preset. Perhaps macosx is required as the build type to run the tests? Perhaps I need to be running the tests in the simulator somehow?
t
I haven't tried tests with new plugin, bit there is an issue in youtrack for simulator tests support
r
Do you have a ticket number for that Ildar? I’d like to follow it. I’ve been trying to figure out simulator test config on the new plugin with no luck so far
t
@spierce7 do you know that you need to build test binary and then run it manually anyway?
We should probably as @Liliia about simulator tests in new plugin
s
"do you know that you need to build test binary and then run it manually anyway?" No. I'm very new to native / iOS programming. I've found examples where people with the old
kotlin-platform-ios
plugin did something like this though:
Copy code
afterEvaluate { project ->
    project.task('test', dependsOn: 'compileTestDebugKotlinNative', type: Exec, overwrite: true) {
        def testExecutable = tasks["compileTestDebugKotlinNative"].outputFile
        commandLine("xcrun", "simctl", "spawn", "iPhone 8", testExecutable)
    }
}
r
Right. So my gradle-fu isn’t great, but essentially what that was doing was replacing the
test
task for the native build with a command to run the ios_x64 test binary on the simulator. On the new plugin though I’ve had two issues: I haven’t been able to figure out the equivalent way to grab the test binary (
tasks["compileTestKotlinIosSim"].outputFile
doesn’t seem to work) and I don’t know how to hook into the correct test step because there isn’t a separate native/ios test task to overwrite.
t
@spierce7 yeah, I've contributed that code to kmpp sample)
s
Where did you contribute it @thevery? I don't see it anywhere.
s
I see, so that's not not with the multiplatform plugin. That's with the old plugin
also, fyi,
commandLine("xcrun", "simctl", "spawn", "iPhone 8", textExecutable)
doesn't work for me. Why would that be?
Copy code
$ xcrun simctl spawn iPhone 8
Invalid device: iPhone
t
You should probably launch simulator.app at least once
l
Any questions to me left here? 🙂
l
Yeah, I also thought so, but decided to make it clear 🙂 Sorry for a long time taken to answer anyway
👌 1