https://kotlinlang.org logo
Title
v

Vivek Mittal

05/23/2023, 6:40 AM
I am building an SDK using kotlin multiplatform for iOS and Android. Most if not all of my code is in commonMain. Can someone please suggest a mocking library? I plan to test in commonTest. I understand some people test in androidTest to use JUnit and Mockito. I don't think that is advisable. I read MocKMP doesn't support commonTest.
j

Joel Denke

05/23/2023, 7:13 AM
I advise not mock at all if you can, use Fakes instead. Or what features do you need mock for?
v

Vivek Mittal

05/23/2023, 9:05 AM
Can I ask why would you advise against mocking? I am trying to mock all dependencies of a class. Same as I have always done on other platforms.
j

Joel Denke

05/23/2023, 10:49 AM
Its a long story, but many companies I worked on and in more vanilla Kotlin best practices the recommendation is going for fakes rather than mocks. Its a lot of details why, but wont list all of them now. Instead of mock dependecies, create fakes for them to emulate what need 🙂 And if any class depend on SDK specific stuff make sure can fake that class so reducing that need.
m

Mustafa Ozhan

05/23/2023, 8:00 PM
I use mockative in my project
j

Joel Denke

05/24/2023, 5:27 AM
Here is the longer story: https://tyrrrz.me/blog/fakes-over-mocks
v

Vivek Mittal

05/30/2023, 5:04 PM
@Mustafa Ozhan Have you been able to use it for testing common code using both android and ios as target?
m

Mustafa Ozhan

05/31/2023, 8:43 AM
Yeap I do, the project is public so you can check here: https://github.com/Oztechan/CCC If you interest only in android&ios you can check the modules in
client
. In
common
i also target to
jvm
for backend. ie the modules in
:client:viewmodel:x
are all has tests for ios & android