I have a multiplatform project and am writing unit...
# multiplatform
r
I have a multiplatform project and am writing unit tests for common code. It appears that Mockk isn't supported yet. Does anyone know how to mock classes in common source sets?
h
you can provide your own test implementation of the classes and mock your implementation something like 👇 https://github.com/android/architecture-samples/tree/master/app/src/mock/java/com/example/android/architecture/blueprints/todoapp
❤️ 1
a
No idea if this works, but is it possible to do the testing on a platform side like JVM?
☝️ 1
a
Don't mock, write fakes 😊
👍 3
r
Yeah I did end up writing a "test" Impl for this test. But in general it's faster and less code to just inject a Mock and verify interaction with the Mock.
Don't mock, write fakes
- @Arkadii Ivanov for higher level tests I can agree on that. But for most unit tests this seems like more unnecessary effort/code.
@Andrew, I could test my code on JVM only, but then I have no tests covering the code for the JS target for example. I'm new to multiplatform, but I thought it would be wise to cover all targets
I'm happy to hear more advice or tips 🙂
a
I don't know enough about JS to answer this, but if you had a pure JS library can you mock unit test that? If so you might be able to do that in Kotlin on the JS module.
a
a
You can also get the best of both by extending a mock class to include default behavior + convenience methods for simpler setup of common setup boilerplate.
Although not applicable to the current question since mock isn't available