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

Janelle Fullen

05/12/2020, 8:56 PM
Has anyone successfully used a unit testing mocking library that works well with MPP? Looking for one.
k

Kris Wong

05/12/2020, 9:13 PM
mockk. though frankly I found it to only handle basic use cases
j

Janelle Fullen

05/12/2020, 9:27 PM
Can you give a little more detail about what works with mockk? Do spies and class mocks work?
k

Kris Wong

05/12/2020, 9:35 PM
to some degree. I recommend you take the time to investigate it.
m

Matt Toal

05/12/2020, 9:37 PM
It looks like it doesn't support ios mocks at all (and maybe struggles with js tests?) https://github.com/mockk/mockk/issues/58
k

Kris Wong

05/12/2020, 10:06 PM
hmm, for some reason I had in my head that it supported k/n
a

Arkadii Ivanov

05/12/2020, 11:19 PM
There is no mocking in kn currently, AFAIK. I switched completely to fakes, even in pure Android projects. I recommend this article: https://medium.com/@june.pravin/mocking-is-not-practical-use-fakes-e30cc6eaaf4e
k

Kris Wong

05/13/2020, 12:40 AM
Personally, I prefer to use DI/SL to swap out test implementations. It seems to work fairly well.
k

Kurt Renzo Acosta

05/15/2020, 1:40 AM
@Arkadii Ivanov by any chance, do you have a project sample with testing using fakes?
a

Arkadii Ivanov

05/15/2020, 9:14 AM
@Kurt Renzo Acosta nothing open at the moment. But there is nothing special. Just abstract dependencies with interfaces and provide test implementations that simulate real ones. Interface segregation principle and functional interfaces really help here.
k

Kurt Renzo Acosta

05/15/2020, 9:19 AM
Great! Looking forward to it. We have some fakes at the moment but I feel like we could do better
👍 1