kotlingradlekotlin-multiplatformmockk

mock common tests in kotlin using multiplatform


I can't use the common mock library ( mockk.io ), with kotlin multiplatform. In their website it says that to use mockk in kotlin multiplatform you just need to add this line to your gradle. testImplementation "io.mockk:mockk-common:{version}"

I added it and it builds normally, only when I want to use it is when it fails. Giving

Unresolved reference: io
Unresolved reference: mockk

my gradle file


kotlin {
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val nativeTarget = when {
        hostOs == "Mac OS X" -> macosX64("native")
        hostOs == "Linux" -> linuxX64("native")
        isMingwX64 -> mingwX64("native")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }

    nativeTarget.apply {
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }
    sourceSets {
        val nativeMain by getting
        val nativeTest by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("io.mockk:mockk-common:1.10.4")
            }
        }
    }
}

Solution

  • Unless something has changed, mockk does not work on Kotlin Native.