Run a single test with gradle, kotest, and Kotlin Multiplatform Mobile

184 views Asked by At

In kotest-examples-multiplatform I can run a single test from the commonTest module with the command:

gradle :jvmTest --tests DataDrivenTest

I've created a new project in https://kmp.jetbrains.com only for iOS and Android development. I've added kotest to the project:

//libs.versions.toml

kotest = "5.8.0"
[libraries]
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
[plugins]
kotestMultiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest" }
//main build.gradle.kts
alias(libs.plugins.kotestMultiplatform) apply false

//:shared build.gradle.kts
plugins {
    alias(libs.plugins.kotestMultiplatform)
}
sourceSets {
    commonMain.dependencies {
        // put your Multiplatform dependencies here
    }
    
    commonTest.dependencies {
        implementation(libs.kotest.assertions.core)
        implementation(libs.kotest.framework.engine)
        implementation(kotlin("test"))
    }
}

I've also added two tests in separate files in the :shared:commonTest module:

class FailTest : StringSpec({

    "fail test" {
        true shouldBe false
    }
})

class SuccessTest : StringSpec({

    "success test" {
        true shouldBe true
    }
})

and with the command:

gradle check

I can run those tests correctly but I can't figure out how to run tests only in a specific class. During development, I'd like to run the test with a single target like android (local) or iosSimulatorArm64. And if I could execute a specific test separately like mentioned here conditional-tests-with-gradle it would be pretty awesome.

0

There are 0 answers