has anyone managed to get mockk working for their ...
# multiplatform
k
has anyone managed to get mockk working for their common tests?
b
What targets do you have in your project?
k
iOS and JVM
m
mockk is not native ready yet, see: https://github.com/mockk/mockk/issues/58
b
Beat me to it ^
k
idea runs JVM tests by default
or I should say, it runs common tests on the JVM
b
We get around this by just using interfaces for a lot of things we plan to mock later in tests. Since you can do in-line
object : SomeInterface …
to make on-the-fly mock implementations
What do you mean by default? Common has to build/run for all targets you support
m
I guess you would need to move tests to jvmTest dir to use mockk
👌 1
k
I mean when you run a test or test class from common with idea, it uses the JVM target
@Mikołaj Kąkol I will give that a try
b
idea had more mature integration with JVM tests, but it can also run them for native targets too
It's also sort of besides the point. Common is supposed to build and run for all targets you support, so if you were running native tests via gradle in CI (or via IDEA just building tests) for example, it would fail to build with mockk in common tests
k
yes, true
i was just trying to get it working with my existing tests
👍 1
after moving the tests to jvmTest, I am getting the same ByteBuddy error
a
I would prefer to write fakes instead of mocks and run tests for iOS as well. Native targets are very special and really need to be tested. The fact that tests are passed on JVM does not mean the code will work on iOS.
k
sure, but there are other hurdles to getting the tests running on iOS because they must run on the simulator
a
Yeah, it is possible to automate everything so you will just run a Gradle task. Worth time investment.
m
Copy code
tasks.register("iosTest") {
        val device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
        val testExecutable = kotlin.targets.getByName<KotlinNativeTarget>("iosX64").binaries.getTest("DEBUG")
        dependsOn(testExecutable.linkTaskName)
        group = JavaBasePlugin.VERIFICATION_GROUP
        description = "Runs tests for target 'ios' on an iOS simulator"

        doLast {
            exec {
                commandLine("xcrun", "simctl", "spawn", "--standalone", device, testExecutable.outputFile.absolutePath)
            }
        }
    }
we do sth like this and it works on Jenkins with mac node
based on some stackoverflow responses on running simulator from gradle
k
yes, that much is straightforward