Does anybody know of a way to run unit tests on co...
# multiplatform
c
Does anybody know of a way to run unit tests on common code, using MockK, on a Mac? Common unit tests build and run OK on Windows machines. But on a mac they won’t run because MockK is not compatible with Kotlin Native. I would be happy for these tests to run on JVM only
m
Mockk is not suited for KMP. You can try KMock, mockative or MocKMP
s
What they said, mockk depends on the JVM. I've been using Mockative instead and not run into any issues
c
Why then does MockK offer a common multiplatform dependency? https://github.com/mockk/mockk#gradlemaven-dependency
m
I believe it is because to play nicely with jvm + android projects
m
It is actually not that simple and the Kotlin Types on non JVM can do crazy stuff...so I do not believe there will be a mockk version soon
c
🤷 I don’t care for iOS Kotlin mocking. All I want to do is run my common code tests using MockK
s
Yeah pretty sure Mockk uses some pretty magical features of the JVM to do it's thing. If you don't care about iOS then just put all your tests in the androidTest module instead of commonTest I guess?
Honestly though Mockative is really not a big learning curve if you already know mockk
m
If you run only with jvm + android...it actually should run
c
This was my initial question
I run
./gradlew shared:check
and it still tries to run them on iOS.
m
As long as you have iOS active in your sources it will not work
c
Is there any easy way to conditionally remove it
like a command line parameter saying ignore iOS
m
No...if you have something else then Jvm + Android you should use one of the alternatives I mentioned
s
I agree with @Matthias Geisler, not being able to run your tests on iOS when you want to run your live code on iOS seems like a bad idea to me. Running the tests against all targeted platforms ensures you're not introducing any platform specific bugs
c
Apart from any expect/actuals I’d hope code in
commonMain
would behave identically on all platforms…
s
So would I, but expect/actuals do exists (and I'm guessing are covered by your tests). And also I sleep better at night knowing that I've got tests making sure the behaviour is consistent across platforms, not just assuming it will be (though I realise this is subjective)
m
No it has not always the same behavior - especially when it comes to concurrency