did someone try to use Mockk on KMM project?
# multiplatform
e
did someone try to use Mockk on KMM project?
h
yes no sorry
n
MockK does not support Kotlin/Native (and by extension part of Kotlin Multiplatform), and in its current form it cannot support it due to how it is implemented technically. About 2 years ago I decided to pick up the challenge to support mocking on Kotlin/Native and Kotlin Multiplatform which gave birth to Mockative, which allows you to mock `interface`s. While it has gained quite a bit of traction, it is not the only option. There is also MocKMP, although I have never used it myself personally.
h
Oh i am mistaken, i use MocKMP 🙃
e
I just added dependencies, but it’s not resolved in Test classes
thanks, it makes sens
@Hylke Bron does MockKMP can mock the static? I want to mock Logger
h
I am not sure, I dont have a requirement to mock statics, my project is set up without any statics involved
n
Neither MocKMP nor Mockative can mock statics, and due to technical reasons it is currently very impractical to write a mocking library that supports mocking statics. It would have to be a Kotlin Compiler Plugin, which are not nearly as trivial to make.
You can refactor your code to inject an instance of a
Logger
interface which you can mock.
j
Fake, ideally. There's no reason to mock a logger.
âž• 1
n
That I agree with @jw 😄
v
Using Mockk on my project. The only catch being I’m only testing
commonMain
. And running it from an Android (JVM) environment (same goes for the CI). On iOS’s side, - not running any tests
1265 Views