In terms of making classes/methods open for mockin...
# android
b
In terms of making classes/methods open for mocking in unit tests … is the best solution for that still to use the kotlin
all-open
plugin, and define annotations in debug and release sourceSets so that annotated classes become open in debug builds, but final in release builds? This is the solution we’ve been using for some time, and it works, no question. But it’s not perfect, because what we really want is for the classes to only be open when running tests, but instead they are open anytime you are doing a debug build, whether for tests or otherwise. I know mockito introduced “inline-mock-maker” awhile back, and at the time it didn’t work with Robolectric. Is that still the case? Is there some other “new and improved” way to keep classes as final but allow them to be mocked in unit tests?
j
Have you tried
mockk
?
b
I’ve looked at it. Haven’t used it myself. Research seems to indicate it’s fairly slow compared to mockito.
however, it seems that recent versions of mockito and robolectric have mitigated the issues above. I was able to write a test just now and successfully mock a kotlin (i.e. final) class.
1
j
Have not benchmarked the unit tests mocks but have not experienced issue described in a long time due to interfaces/fakes and mockk