https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Rachid

06/05/2020, 2:40 PM
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

Himanshu Sharma

06/05/2020, 5:40 PM
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

Andrew

06/05/2020, 6:03 PM
No idea if this works, but is it possible to do the testing on a platform side like JVM?
☝️ 1
a

Arkadii Ivanov

06/05/2020, 10:40 PM
Don't mock, write fakes 😊
👍 3
r

Rachid

06/08/2020, 7:25 PM
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

Andrew

06/08/2020, 7:50 PM
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

Arkadii Ivanov

06/08/2020, 8:23 PM
a

Andrew

06/08/2020, 9:39 PM
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