Unfortunately, the mockito-android mockmaker is not very useful in the modern Android ecosystem. It relies entirely on the subclass mockmaker, so it cannot mock final classes. The Android ecosystem has become increasingly Kotlin centric - both Google's first-party libraries and app code. In Kotlin all classes are final by default unless explicitly marked with open keyword. This means mockito-android is not able to mock much at all.
For a long time our Android teams have been using https://github.com/linkedin/dexmaker with dexmaker-mockito-inline to support Mockito in Android tests. It has a mockmaker that does special bytecode generation for Dalvik.
As a point of comparison, MockK (I would say Mockito's biggest competitor in the Kotlin world) seems to have copied/forked dexmaker-mockito-inline in their Android "proxy" implementation:
https://github.com/mockk/mockk/blob/master/modules/mockk-agent-android/README.txt
A downside of dexmaker-mockito-inline for a while was that it only supported Android P (API 28) and up, but according to Android Studio's version distribution dialog this accounts for > 95% of distribution. It doesn't seem like much of a limitation at this point.
I'd like to replace mockito-android's mock maker implementation with one built on top of dexmaker. Any concerns about this?
dexmaker has an Apache 2.0 license so I think it would be okay to include its source. Maybe a better option would be to explicitly take a dependency or discuss transferring ownership?
Unfortunately, the
mockito-androidmockmaker is not very useful in the modern Android ecosystem. It relies entirely on the subclass mockmaker, so it cannot mock final classes. The Android ecosystem has become increasingly Kotlin centric - both Google's first-party libraries and app code. In Kotlin all classes are final by default unless explicitly marked withopenkeyword. This meansmockito-androidis not able to mock much at all.For a long time our Android teams have been using https://github.com/linkedin/dexmaker with
dexmaker-mockito-inlineto support Mockito in Android tests. It has a mockmaker that does special bytecode generation for Dalvik.As a point of comparison, MockK (I would say Mockito's biggest competitor in the Kotlin world) seems to have copied/forked dexmaker-mockito-inline in their Android "proxy" implementation:
https://github.com/mockk/mockk/blob/master/modules/mockk-agent-android/README.txt
A downside of dexmaker-mockito-inline for a while was that it only supported Android P (API 28) and up, but according to Android Studio's version distribution dialog this accounts for > 95% of distribution. It doesn't seem like much of a limitation at this point.
I'd like to replace mockito-android's mock maker implementation with one built on top of dexmaker. Any concerns about this?
dexmaker has an Apache 2.0 license so I think it would be okay to include its source. Maybe a better option would be to explicitly take a dependency or discuss transferring ownership?