-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use multiplatform mocking library for tests #5420
Comments
I started to look into this. Here are some preliminary research results:
|
Nice! Many thanks for the deep research! Very cool that you even found a bug in the (it looks like) otherwise seemingly most fitting library, and also created a PR. We will see how the maintainer handles these. With Mockative, are only classes mockable that are annotated with |
There's a way to do it without the attribute, but it might not work.
|
I see, so maybe just using interfaces might be the cleanest solution. Even though it will lead to some boilerplate code, there is at least not black magic involved. (But this decision can certainly be postponed until the time when we actually have a KMP setup and migrate the tests from javaTest to commonTest. Theoretically, we could just keep all the tests in jvmTests, too) |
The comment in mockative/mockative#100 (comment) of the main maintainer of Mockative is sadly not inspiring confidence in the continued development and support of Mockative for Kotlin 2. Mokkery has seen a lot of development in the last months and looks promising in this regard. And it already has support for Kotlin 2. But I still have to check it out and see if it has all the features we need for the tests. |
Hm, this is sad, as you've put so much effort into integration with Mockative already. Both Mockative and MocKMP seem to have the same issue with K2. I do wonder whether the maintainers of these two libraries know of Mokkery? Maybe they want to take a similar approach with making their libraries K2-compatible. Then on the other hand, I don't know how bug such a mocking library is. Maybe if they would do that, they would just end up having a Mokkery in green. |
The maintainer of Mockative knows of Mokkery. They commented about it somewhere in the Mockative issues, that's how I found Mokkery in the first place. They also commented on a Mokkery ticket about recursive / chain mocking. MockKMP seems to be dead / unmaintained. |
For mocking unit tests, we are currently using the Java library
org.mockito:mockito
.In order that the tests for platform-independent application logic can be executed on any supported platform, mockito needs to be replaced as a test dependency.
Mocking library requirements
multiplatform support for at least Java/Android and iOS
stable, well-tested and ideally (semi-)official / well-maintained
support all features of Mockito we are using now
It is possible that when migrating, a bit more effort is necessary because as far as I know, Mockito uses Java reflection to create the mocks, which is a Java specific language feature. In other words, it may not be possible to mock non-interfaces.
Three Kotlin Multiplatform libraries for mocking are known to me, with a few comments from a short look at them, ordered by popularity on github:
Mockative
MocKMP
MockingBird
The text was updated successfully, but these errors were encountered: