Skip to content

Proposal: integrate dexmaker-mockito-inline for modern Android support #3788

Closed

Description

@jselbo

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?

Activity

  1. raphw commented on Feb 6, 2026

    @raphw
    Member

    I think this is a fair suggestion. The module lifes on the side anyways, so as long as we provide it, it can cater to the majority of users. People who want to support older Android versions can simply rely on older versions of Mockito. What do you think @mockito/developers

  2. added 2 commits that reference this issue on Feb 25, 2026
    24af0c6
    f873865
  3. jselbo commented on Mar 13, 2026

    @jselbo
    CollaboratorAuthor

    Closed by #3792

  4. faenil commented on Sep 9, 2026

    @faenil

    hi @jselbo the new dependency on dexmaker seems to cause an incompatibility between mockito-android and mockk-android, is that known?

    2 files found with path 'dispatcher.jar' from inputs:
     - io.mockk:mockk-agent-android:1.14.11/classes.jar
     - com.linkedin.dexmaker:dexmaker-mockito-inline:2.28.6/classes.jar
    Adding a packaging block may help, please refer to
    https://developer.android.com/reference/tools/gradle-api/com/android/build/api/dsl/Packaging
    for more information
    

    Unfortunately MockK packages its own dispatcher.jar, so it's not even the same content, i.e. you can't just pick any of the two to keep in the final artifact

    At first look I'm tempted to say this would be easily fixed by MockK renaming the jar to clarify it's mockk's version, but I was wondering if there's anything that can be done on this side of the fence

  5. jselbo commented on Sep 9, 2026

    @jselbo
    CollaboratorAuthor

    I wasn't aware of the issue before but that makes sense. Do you mind filing a separate issue?

    We can probably fix like you said on the Mockito side by just renaming the jar.

    As a temporary workaround I wonder if you could do some Gradle hacking to repackage the .aar renaming the dispatcher.jar . Or just wait to upgrade until we can publish a fixed version

  6. bric3 commented on Sep 10, 2026

    @bric3
    Member

    Also, maybe open a new issue on mockito so folk can track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions