Skip to content

Bug: Kotlin multiplatform project fails to build with mockk dependency #322

Open
@littleGnAl

Description

@littleGnAl

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
    I checked the documentation and found no answer
    I checked to make sure that this issue has not already been filed

Current Behavior

I'm working on a kotlin multiplatform project, when I try to write some unit test by using MockK, I got the Unresolved reference: xxx error when I run the ./gradlew :common:build, don't actually know this case relates to this issue(#58 ) or not.

...

> Task :common:linkTestDebugExecutableIos FAILED
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (3, 8): Unresolved reference: io
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (4, 8): Unresolved reference: io
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (5, 8): Unresolved reference: io
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (11, 4): Unresolved reference: MockK
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (18, 5): Unresolved reference: MockKAnnotations
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (26, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (40, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (52, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (59, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (66, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (73, 5): Unresolved reference: verify
e: xxx/accounting-multiplatform/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt: (80, 5): Unresolved reference: verify
8 actionable tasks: 8 executed
19:05:52: Task execution finished 'build'.


Steps to Reproduce

You can clone the project https://github.com/littleGnAl/accounting-multiplatform/tree/littlegnal/common-test.

Uncomment the https://github.com/littleGnAl/accounting-multiplatform/blob/littlegnal/common-test/android/common/src/commonTest/kotlin/com/littlegnal/accountingmultiplatform/data/SqlDelightManagerTest.kt.

Then run the ./gradlew :common:build to reproduce

Context

My gradle configuration is like below:

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'com.squareup.sqldelight'
apply plugin: 'kotlinx-serialization'

sqldelight {
    AccountingDB {
        packageName = "com.littlegnal.accountingmultiplatform"
    }
}

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation deps.kotlin.stdlib.stdlib
                implementation deps.kotlin.serialiaztion.runtime.common
                implementation deps.kotlin.coroutines.common
            }
        }

        commonTest {
            dependencies {
                implementation deps.kotlin.coroutines.core
                implementation deps.kotlin.coroutines.common
                implementation deps.kotlin.coroutines.test
                implementation deps.kotlin.test.common
                implementation deps.kotlin.test.annotations
//                implementation deps.mockk.common
//                implementation deps.mockk.mockk
                implementation "io.mockk:mockk-common:1.9.3"
                implementation "io.mockk:mockk:1.9.3"

            }
        }

        androidTest {
            dependencies {
                implementation deps.kotlin.test.test
                implementation deps.kotlin.test.junit
            }
        }

        androidMain {
            dependencies {
                implementation deps.kotlin.stdlib.stdlib
                implementation deps.sqldelight.runtimejvm
                implementation deps.kotlin.serialiaztion.runtime.runtime
                implementation deps.kotlin.coroutines.android
            }
        }

        iosMain {
            dependencies {
                implementation deps.kotlin.stdlib.stdlib
                implementation deps.sqldelight.driver.ios
                implementation deps.kotlin.serialiaztion.runtime.native
                implementation deps.kotlin.coroutines.native
            }
        }

        iosTest {
            dependencies {
                implementation "io.mockk:mockk-common:1.9.3"
                implementation "io.mockk:mockk:1.9.3"
            }
        }
    }

    targets {
        fromPreset(presets.jvm, 'android')
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
                              ? presets.iosArm64 : presets.iosX64

        fromPreset(iOSTarget, 'ios') {
            binaries {
                framework('common')
            }
        }
    }
}

// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
    compileClasspath
}

task packForXCode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
    final def framework = kotlin.targets.ios.binaries.getFramework("common", mode)

    inputs.property "mode", mode
    dependsOn framework.linkTask

    from { framework.outputFile.parentFile }
    into frameworkDir

    doLast {
        new File(frameworkDir, 'gradlew').with {
            text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
            setExecutable(true)
        }
    }
}

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
        }
    }
}

tasks.build.dependsOn packForXCode
  • MockK version: 1.9.3
  • OS: macOS Mojave 10.14.4
  • Kotlin version: 1.3.31
  • Type of test: unit test OR android instrumented test: Unit test

Activity

oleksiyp

oleksiyp commented on Jun 24, 2019

@oleksiyp
Collaborator

Thanks for the report

AdibaM

AdibaM commented on Jul 31, 2019

@AdibaM

Did you find a work around for this?

Bradleycorn

Bradleycorn commented on Sep 18, 2019

@Bradleycorn

same issue here ... any way to work around this?

desgraci

desgraci commented on Oct 1, 2019

@desgraci

Same issue Kotlin version: 1.3.50

added this to the 1.9.4 milestone on Nov 1, 2019
changed the title [-]Unresolved reference when run the task linkTestDebugExecutableIos in kotlin multiplatform project[/-] [+]Bug: Kotlin multiplatform project fails to build with mockk dependency[/+] on Nov 1, 2019
heinhtetaung92

heinhtetaung92 commented on Mar 19, 2020

@heinhtetaung92

Hello. Same here. Any update on this?

danielocampo2

danielocampo2 commented on Jun 18, 2020

@danielocampo2

Had the same issue. For now I had to stop using mockk altogether for KMP as I don't know any workaround.

Is there any update?

Thanks!

xiaobailong24

xiaobailong24 commented on Sep 4, 2020

@xiaobailong24

Same issue with Kotlin multiplatform-1.4.0. Except new update to fix it.

jcfuerte

jcfuerte commented on Oct 10, 2020

@jcfuerte

Same Issue, someone has an update for this?

Thanks!

Ornolfr

Ornolfr commented on Oct 21, 2020

@Ornolfr

Any workaround available?

danielocampo2

danielocampo2 commented on Oct 21, 2020

@danielocampo2

I think basically mockk has no support for Kotlin Multiplatform so it is not possible to use this library with it.

jcfuerte

jcfuerte commented on Oct 21, 2020

@jcfuerte

I think basically mockk has no support for Kotlin Multiplatform so it is not possible to use this library with it.

probably soon it could be supported

21 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @scottnj@rocketraman@pedrofraca@desgraci@silverhammermba

        Issue actions

          Bug: Kotlin multiplatform project fails to build with mockk dependency · Issue #322 · mockk/mockk