Replace mockito-android mock maker with dexmaker-mockito-inline fork#3789
Closed
jselbo wants to merge 2 commits intomockito:mainfrom
Closed
Replace mockito-android mock maker with dexmaker-mockito-inline fork#3789jselbo wants to merge 2 commits intomockito:mainfrom
jselbo wants to merge 2 commits intomockito:mainfrom
Conversation
…line Fork dexmaker-mockito-inline (v2.28.4) to replace the ByteBuddy subclass-based mock maker with a JVMTI-based inline mock maker that supports mocking final classes and methods on Android. Key changes: - Convert mockito-android from Java library (JAR) to Android library (AAR) - Add native NDK/CMake code (JVMTI agent + AOSP slicer library) - Fork dexmaker Java sources under org.mockito.android.internal.creation.inline - Update JNI function names in agent.cc to match new package - Add InlineAndroidMockMaker entry-point delegating to InlineDexmakerMockMaker - Build dispatcher.jar from source via mockito-android-dispatcher submodule - Require min SDK 28 (Android P) for JVMTI support - Conditionally include mockito-android based on Android SDK availability - Add integration tests for final class mocking Fixes mockito#3788
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3789 +/- ##
============================================
+ Coverage 86.50% 86.90% +0.40%
+ Complexity 3004 2997 -7
============================================
Files 343 340 -3
Lines 9099 9021 -78
Branches 1121 1105 -16
============================================
- Hits 7871 7840 -31
+ Misses 945 905 -40
+ Partials 283 276 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
raphw
approved these changes
Feb 27, 2026
Member
|
I do not know enough on the background to decide if forking or linking is the better solution, but I wonder: Instead of forking, we could probably simply depend on the dexmaker-mockito-inline artifact. The downside of this seems to be lack of control and limiting future improvements. If the limitation is in the future and if no API is exposed, could we go for linking until we need to potentially fork? |
Collaborator
Author
|
Thinking about it more, I think linking for now makes sense for simplicity. I will open a new PR. |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fork dexmaker-mockito-inline (https://github.com/linkedin/dexmaker/tree/main/dexmaker-mockito-inline) to replace the subclass-based mock maker with a JVMTI-based inline mock maker that supports mocking final classes and methods on Android.
This allows Mockito to be useful in a modern Kotlin Android ecosystem where classes are
finalby default unless explicitly marked with theopenkeyword. The subclass mock maker cannot mock final classes, and the inline mock maker does not work on Android.Users currently work around this limitation by:
opento owned Kotlin classes they want to mockRisks/Considerations:
jartoaarwill be transparent for Gradle users, but not sure about other build systems.external/:jdk/jvmti.his from Oracle OpenJDK under GPL-2.0slicer/is from AOSP under Apache 2.0agent.ccand all new Java sources exceptInlineAndroidMockMaker.javaare copied from dexmaker-mockito-inline licensed under Apache 2.0. Confusingly, the headers of these sources state "Copyright (C) 2017 The Android Open Source Project" even though they seem to originate from the dexmaker repo itself. I opened License headers? linkedin/dexmaker#208 asking about this. I retained the headers as-is.Technical changes:
Note for reviewers: the only "new" code is InlineAndroidMockMaker.java. Everything else is a copy/fork.
Fixes #3788
Checklist
This adds a new compile dependency for mockito-android on
com.linkedin.dexmaker:dexmakerwhich allows runtime generation of Android dex byte code, similar to Byte-Buddy on the JVM.