Hello! Is there library for mocking common code? ...
# multiplatform
m
Hello! Is there library for mocking common code? I have some classes in common code and I would like to write unit tests, so I need to mock their dependencies. Which library is suitable for that?
d
I use mockk.io
m
But Mockk is for JVM only, isn't it?
d
Yes, but if the code you test is pure Kotlin without platform specific dependencies (different from JVM), you can run your tests on the JVM without an issue.
m
But in real application at least part of common code will be executing in JS. So I feel right to check it too. For example, this way I found bug in serialization which won't work in JS
Test in JVM only is better than have no tests at all, of course
d
I think I didn't get what you're trying to achieve there. Do you want to test pure Kotlin components in the common code with unit tests our are you testing platform specific code that depend in the common code that you want to mock?
m
I would like to mock platform-specific code and test common code.
d
Could you share a simple example, please
d
Why not to use the platform especifc then? You could test the common code and then test the platform especific
m
If I use platform-specific mocks I have to write all unit tests twice - for JVM and for JS
d
Perhaps you could create an abstraction for the platform specific code, so you can mock it when you test the common part. Same thing for vice versa