Coder Social home page Coder Social logo

tmurakami / dexopener Goto Github PK

View Code? Open in Web Editor NEW
113.0 5.0 4.0 1.41 MB

An Android library that provides the ability to mock your final classes on Android devices.

License: Apache License 2.0

Java 97.84% Shell 2.16%
android android-testing test-instrumentation-runner mock mocking

dexopener's People

Contributors

tmurakami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dexopener's Issues

Dexopener not working

after applying this lib to my project i still get the error below

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.



IMPORTANT INFORMATION FOR ANDROID USERS:

The regular Byte Buddy mock makers cannot generate code on an Android VM!
To resolve this, please use the 'mockito-android' dependency for your application:
http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22mockito-android%22%20g%3A%22org.mockito%22

Java               : 0.9
JVM vendor name    : The Android Project
JVM vendor version : 2.1.0
JVM name           : Dalvik
JVM version        : 0.9
JVM info           : null
OS name            : Linux
OS version         : 4.4.116-g8a6cc9c6abe9

Here is my custom test runner

class CustomTestRunner: AndroidJUnitRunner() {

    override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
        DexOpener.install(this)
        return super.newApplication(cl, className, context)
    }

}

Here is my build gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-allopen'

android {
    compileSdkVersion 28
    testOptions.unitTests.includeAndroidResources = true
    defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunner 'com.myproject.CustomTestRunner'
        testInstrumentationRunnerArguments clearPackageData: 'true'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug{

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    useLibrary 'android.test.runner'

    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'

}

repositories {
    maven { url 'https://jitpack.io' }
}

allOpen {
    // allows mocking for classes w/o directly opening them for release builds
    annotation 'com.myproject.test.OpenClass'
}

dependencies {
    def lifecycle_version = "2.0.0"
    def mockito = "2.21.0"
    def mockito_android = "2.23.4"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    //network lib
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

    //Android architecture libs
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

    implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"

    // Koin for Android
    implementation 'org.koin:koin-android:1.0.2'
    // Koin for Lifecycle scoping
    implementation 'org.koin:koin-androidx-scope:1.0.2'
    //Koin for Android Architecture ViewModel
    implementation 'org.koin:koin-androidx-viewmodel:1.0.2'

    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

    //room db
    kapt 'androidx.room:room-compiler:2.1.0-alpha03'
    implementation 'androidx.room:room-runtime:2.1.0-alpha03'
    implementation 'androidx.room:room-testing:2.1.0-alpha03'

    //android instrumental test
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.ext:truth:1.1.0'
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation('androidx.arch.core:core-testing:2.0.0') {
        exclude group: 'org.mockito:mockito-core'
    }
    androidTestUtil 'androidx.test:orchestrator:1.1.1'
    androidTestImplementation 'com.github.tmurakami:dexopener:2.0.0'

    androidTestImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    androidTestImplementation 'com.jraska.livedata:testing:0.6.0'

//    androidTestImplementation "org.mockito:mockito-core:$mockito"
    androidTestImplementation"org.mockito:mockito-android:$mockito_android"
//        exclude group: 'org.mockito'
//    }

    androidTestImplementation('org.koin:koin-test:1.0.2') {
        exclude group: 'org.mockito'
    }

//    androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.21.0'

//    androidTestImplementation ("org.mockito:mockito-inline:$mockito"){
//        exclude group: 'org.mockito'
//    }

    //unit test
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-core:$mockito"
    testImplementation "org.mockito:mockito-android:$mockito"
    testImplementation "org.mockito:mockito-inline:$mockito"
    testImplementation 'org.koin:koin-test:1.0.2'
    testImplementation 'androidx.test.ext:junit:1.1.0'
    testImplementation 'androidx.arch.core:core-testing:2.0.0'
    testImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    testImplementation 'com.jraska.livedata:testing:0.6.0'
    testImplementation 'androidx.test.ext:truth:1.1.0'
}

Package path

Continueing on #20 and by looking at the implementation I don't see a reason why the user of this library shouldn't be able to define one or more package paths to "open" himself. IMHO the "reasonable default" that the JUnit runner must reside inside the root path and that all modules must have either the same root path or have packages underneath that sounds like an artificial limitation.

Could you elaborate a bit more what made you do this decision?

DexOpener.Builder example in README misled me

Hi,
Thanks for this great library, I can finally mock my Kotlin classes! I tried to follow the instructions for DexOpener.Builder in the README and couldn't get it working until I followed the version in the sample code, which just uses return super.newApplication(cl, className, context).
Maybe update it to just use that?

UI Tests fail on API 23, but not on API 24+

Hello Tsuyoshi,

DexOpener is pretty much the only way we have found to be able to test using Espresso and Mockito along with Kotlin. I have spent some time today trying to figure out why a project I've been working on fails on Android versions lower than 24, but works fine on API 24+. I find that DexOpener is one of the components that seems to make a difference. We were using 0.10.3 of DexOpener, and the behaviour is slightly different with that version, so I decided to upgrade, and then the behaviour changes quite a bit more.

I have been working on getting this to fail on a smaller, non-proprietary project, and have succeeded. I end up getting the following error when run in an API 23 Emulator:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.robotsandpencils.kotlindaggerexperiement/com.robotsandpencils.kotlindaggerexperiement.presentation.main.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property dispatchingActivityInjector has not been initialized
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property dispatchingActivityInjector has not been initialized
at com.robotsandpencils.kotlindaggerexperiement.App.activityInjector(App.kt:52)
at dagger.android.AndroidInjection.inject(AndroidInjection.java:56)
at com.robotsandpencils.kotlindaggerexperiement.presentation.main.MainActivity.onCreate(MainActivity.kt:42)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:624)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)

But the same code runs fine in API 24 and higher.

The project is on Github: https://github.com/nealsanche/KotlinDagger2Experiment

I wonder if you might have a look and see if there's anything you can suggest. This project seems to also run fine when using the 0.10.3 version of DexOpener (though my larger proprietary project does not).

Instrumented test crashes using version 1.0.4 in Android Studio 3.1.2

java.io.IOError: java.io.IOException: Cannot create /data/user/0/com.mypackage.debug/code_cache/dexopener
at com.github.tmurakami.dexopener.repackaged.com.github.tmurakami.classinjector.InjectorClassLoader.injectClass(InjectorClassLoader.java:58)
at com.github.tmurakami.dexopener.repackaged.com.github.tmurakami.classinjector.InjectorClassLoader.findClass(InjectorClassLoader.java:42)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.installProvider(ActivityThread.java:6227)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.IOException: Cannot create /data/user/0/com.mypackage.debug/code_cache/dexopener
at com.github.tmurakami.dexopener.DexFileGenerator.generateDexFile(DexFileGenerator.java:39)
at com.github.tmurakami.dexopener.AndroidClassSource$DexFileTask.call(AndroidClassSource.java:171)
at com.github.tmurakami.dexopener.AndroidClassSource$DexFileTask.call(AndroidClassSource.java:142)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Cannot find BuildConfig if applicationId changed for product flavor

Say my source code uses the package name a.b.c

Now I add a couple product flavors, f1 and f2, changing my defaultConfig applicationId to a.b.
f1 adds applicationIdSuffix ".d".
while f2 adds applicationIdSuffix ".c", keeping the original package name.

It turns out that I can run Android tests for the variant f2 but when using f1 I get the IllegalStateException that the BuildConfig can't be found.

My setup is a bit more complicated than this example but this should be enough to illustrate the issue. My BuildConfig class will always be a.b.c.BuildConfig even when the application ID is a.b.d.

The workaround is to use the deprecated Builder to specify the BuildConfig class. I'm expecting this will be inaccessible soon so I'm highlighting that there should still be a way to specify the BuildConfig manually.

Some devices won't run tests: "java.lang.VerifyError: Rejecting class X because it failed compile-time verification"

This is a strange one. I am running the same test package including dexopener on different devices. For some the tests run normally and for others the tests won't start because of this error. Here is the entire output for the test run on one of the failing devices:

06-01 14:46:57.454 I/art: Late-enabling -Xcheck:jni
06-01 14:46:57.454 I/art: VMHOOK: rlim_cur : 0 pid:4547
06-01 14:46:57.489 I/art: Debugger is no longer active
06-01 14:46:57.589 I/MultiDex: VM with version 2.1.0 has multidex support
06-01 14:46:57.589 I/MultiDex: install
06-01 14:46:57.590 I/MultiDex: VM has multidex support, MultiDex support library is disabled.
06-01 14:46:58.992 I/art: Background sticky concurrent mark sweep GC freed 177210(11MB) AllocSpace objects, 19(708KB) LOS objects, 19% free, 41MB/51MB, paused 5.139ms total 72.868ms
06-01 14:47:00.495 I/art: Background sticky concurrent mark sweep GC freed 216115(13MB) AllocSpace objects, 19(708KB) LOS objects, 22% free, 42MB/54MB, paused 6.577ms total 76.864ms
06-01 14:47:01.277 I/art: override thread count:-j4
06-01 14:47:02.687 I/art: override thread count:-j4
06-01 14:47:02.988 W/art: Verification of   .network.ClientCallback com.redacted.activity.ActivityTestBase.getClientCallback() took 1.321s
06-01 14:47:04.332 I/art: override thread count:-j4
06-01 14:47:04.653 W/art: Verification of void com.redacted.activity.ActivityTestBase.setUp() took 1.661s
06-01 14:47:04.654 E/AndroidRuntime: FATAL EXCEPTION: main
                                     Process: com.redacted.test, PID: 4547
                                     java.lang.VerifyError: Rejecting class com.redacted.activity.RedactedActivityTest because it failed compile-time verification (declaration of 'com.redacted.activity.RedactedActivityTest' appears in /data/data/com.redacted.test/code_cache/dexopener/classes-1967783184.zip)
                                         at java.lang.reflect.Constructor.newInstance(Native Method)
                                         at junit.framework.TestSuite.createTest(TestSuite.java:61)
                                         at junit.framework.TestSuite.addTestMethod(TestSuite.java:294)
                                         at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
                                         at junit.framework.TestSuite.<init>(TestSuite.java:129)
                                         at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
                                         at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:149)
                                         at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:57)
                                         at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:78)
                                         at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
                                         at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
                                         at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:371)
                                         at com.android.test.runner.MultiDexTestRunner.onCreate(MultiDexTestRunner.java:31)
                                         at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4991)
                                         at android.app.ActivityThread.access$1600(ActivityThread.java:150)
                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1455)
                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                         at android.os.Looper.loop(Looper.java:168)
                                         at android.app.ActivityThread.main(ActivityThread.java:5781)
                                         at java.lang.reflect.Method.invoke(Native Method)
                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)

We have successes on a Samsung Galaxy S6 Marshmallow, a Google Nexus 6 Lollipop, and a Google Pixel C Nougat.
We have failures on a Samsung Galaxy S7 Marshmallow and an HTC One A9 Marshmallow.
So there doesn't seem to be a pattern of why one device should pass and the other fail.

Using multidex + "dexopener" - java.lang.NoClassDefFoundError

Reposted from: mockito/mockito#1082 (comment)

Starting 0 tests on emulator-5554 - 4.4.2
Tests on emulator-5554 - 4.4.2 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

com.android.builder.testing.ConnectedDevice > No tests found.[emulator-5554 - 4.4.2] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/<>/repo/android-gif-example/build/reports/androidTests/connected/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 6s
94 actionable tasks: 39 executed, 55 up-to-date

Version of dexmaker - 0.10.1

I was using my example project here: https://github.com/jaredsburrows/android-gif-example

Using a Spy on TestApplication

Running this code:

DexOpener.install(this)
    return Mockito.spy(super.newApplication(cl, "com.xyz.test.TestApp", context))

gives me this error

org.mockito.exceptions.base.MockitoException: 
    Mockito cannot mock this class: class com.xyz.test.TestApp

Do you know any way I can place a spy on my custom Application class so that I can mock some methods on it?

My setup is working when I remove the spy.

`Verification of X took Nms` repeats very slowly for EVERYTHING...

does this for my classes, library classes, almost everything.
e.g.:

05-24 12:43:22.852 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(int, int) took 147.824ms
05-24 12:43:22.992 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(int, int, java.util.concurrent.Callable) took 139.386ms
05-24 12:43:23.132 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(long, long, java.util.concurrent.TimeUnit, io.reactivex.Scheduler, java.util.concurrent.Callable) took 140.788ms
05-24 12:43:23.272 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(io.reactivex.ObservableSource, io.reactivex.functions.Function, java.util.concurrent.Callable) took 137.164ms
05-24 12:43:23.412 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(io.reactivex.ObservableSource, java.util.concurrent.Callable) took 140.923ms
05-24 12:43:23.552 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.buffer(java.util.concurrent.Callable, java.util.concurrent.Callable) took 141.834ms
05-24 12:43:23.702 W/art: Verification of io.reactivex.Observable io.reactivex.Observable.cache() took 148.045ms

Anyway, this whole thing doesn't start until the test starts... in my case it's an Activity test so eventually the rule times out the activity launch at 45 seconds and so we fail.

Running a single instrumentation test on a Marshmallow device using AndroidJUnit4. My app is MultiDex, so here's my test runner:

public class MultiDexJUnitTestRunner extends AndroidJUnitRunner {
    @Override
    public void onCreate(Bundle arguments) {
        MultiDex.install(getTargetContext());
        super.onCreate(arguments);
    }

    @Override
    public Application newApplication(ClassLoader cl, String className, Context context)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        DexOpener.install(this);
        return super.newApplication(cl, className, context);
    }
}

Though the same symptom happened even if I comment out the MultiDex stuff, so that doesn't seem to be the reason...

RuntimeException occurs when minSdkVersion is 26

Smali does not support Dex format version 038.

Logcat is here:

06-09 20:35:12.769  4389  4389 E AndroidRuntime: FATAL EXCEPTION: main
06-09 20:35:12.769  4389  4389 E AndroidRuntime: Process: com.example.myapplication, PID: 4389
06-09 20:35:12.769  4389  4389 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.example.myapplication.test.TestApp: com.github.tmurakami.dexopener.repackaged.org.jf.dexlib2.util.DexUtil$UnsupportedFile: Dex version 038 is not supported
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5793)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.ActivityThread.-wrap1(Unknown Source:0)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:105)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6540)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: Caused by: com.github.tmurakami.dexopener.repackaged.org.jf.dexlib2.util.DexUtil$UnsupportedFile: Dex version 038 is not supported
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.repackaged.org.jf.dexlib2.util.DexUtil.verifyDexHeader(SourceFile:94)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.repackaged.org.jf.dexlib2.dexbacked.DexBackedDexFile.<init>(SourceFile:78)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.repackaged.org.jf.dexlib2.dexbacked.DexBackedDexFile.<init>(SourceFile:104)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.DexFilesFactory.newDexFiles(DexFilesFactory.java:39)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.AndroidClassSource.newDelegate(AndroidClassSource.java:64)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.AndroidClassSource.getDelegate(AndroidClassSource.java:44)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.AndroidClassSource.getClassFile(AndroidClassSource.java:38)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.github.tmurakami.dexopener.repackaged.com.github.tmurakami.classinjector.StealthClassLoader.findClass(SourceFile:32)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at com.example.myapplication.test.TestApp.onCreate(TestApp.kt:11)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:323)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5790)
06-09 20:35:12.769  4389  4389 E AndroidRuntime: 	... 8 more

ockito-android"

ava.lang.NoClassDefFoundError: org/mockito/internal/configuration/plugins/Plugins
at org.mockito.internal.configuration.GlobalConfiguration.tryGetPluginAnnotationEngine(GlobalConfiguration.java:55)


Since Mockito-android is so large, I had to use LinkedIn's dexmaker.

Mocking final methods in Android platform classes

Am I correct in understanding that only final classes and methods that are created in our projects can be mocked with this library? I am trying to mock Activity.getApplication(), which is final and isn't normally possible with mockito-android, and it seems that this library isn't able to help there either. I think this limitation is described in the README, "Mockable final classes and methods are restricted under the package of the app's BuildConfig", but that wasn't initially clear to me.

Perhaps this limitation could be clarified in the library's main description. When I read, "A library that provides the ability to mock final classes and methods on Android", I thought it meant any final class or method anywhere (from the platform, a library, etc.).

java.lang.IncompatibleClassChangeError on Android 5.0-6.0

Exception message in runtime:

Class 'ua.pl.mik.app.DaggerAppComponent$SomeLongNameBuilder' does not implement interface 'ua.pl.mik.app.net.ApiComponent$Builder' in call to 'ua.pl.mik.app.net.ApiComponent ua.pl.mik.app.net.ApiComponent$Builder.build()

Class names was changed a bit.
On Android 7.0+ same apks (main + androidTest) working fine.

Mockito cannot mock/spy final class

Hi, I have a question related with your library. Can I mock classes with are under other modules of my project? For example, projects usually have three modules: view, domain and data. When I run my test, it says that one class from my data module cannot be mocked. I think is related with this:

"The final classes/methods you can mock are only those under the package of your app's BuildConfig. Therefore, you cannot mock final classes/methods you don't own, such as Android system classes and third-party libraries."

But in my case, I do own that classes, but they are in other modules in my project. Is there any way to workaround this?

Cannot execute test

Hi, when I execute my test, I get:

Running tests

$ adb shell am instrument -w -r   -e debug false 
example.org.test/com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner
Client not ready yet..
Started running tests
Test running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.

I have configured my build.gradle as readme says.

"mockito-android" + "dexopener" - java.lang.NoClassDefFoundError: org/mockito/internal/configuration/plugins/Plugins

Reposted from: mockito/mockito#1082 (comment)

java.lang.NoClassDefFoundError: org/mockito/internal/configuration/plugins/Plugins
        at org.mockito.internal.configuration.GlobalConfiguration.tryGetPluginAnnotationEngine(GlobalConfiguration.java:55)

Since Mockito-android is so large, I had to use LinkedIn's dexmaker.

Version of dexmaker - 0.9.2

I was using my example project here: https://github.com/jaredsburrows/android-gif-example

How to deal with package id different from class package

We started long time ago and we didn't have name for app yet. So our main package is com..

Before release, we finalised name of the app and it is stated in our build.gradle. However, package name in sources was not changed.

I'm trying now to use dexopener but I'm getting error from mockito that it can not mock the class.

In addition, it fails to on non final java class and non final method (I would expect it to fail on Kotlin class).

Any help with it?

java.lang.ClassNotFoundException thrown when using multidex

I'm using api 26, with multidex enabled.
My gradle.build for app:

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.wabadaba.dziennik"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 5
        versionName "0.4"
        flavorDimensions "versionCode"
        testInstrumentationRunner 'com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner'
        multiDexEnabled true
        testBuildType 'debug'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
            multiDexKeepFile file('multidex-config.txt')
        }
    }
}
dependencies{
    androidTestImplementation 'com.github.tmurakami:dexopener:0.11.0'
}

I already added a multidex-config.txt file in the same directory:

com/wabadaba/dziennik/BuildConfig.class

Full logcat output:

I: Not late-enabling -Xcheck:jni (already on)
W: Unexpected CPU variant for X86 using defaults: x86
W: Zip open failed: Failure to verify dex file '/data/app/com.wabadaba.dziennik.test-mpAczVGBtCHcMZ9NDzO8OQ==/base.apk:classes2.dex': Invalid field name: 'Verify no further interactions'
W: ClassLoader referenced unknown path: 
D: Shutting down VM
E: FATAL EXCEPTION: main
   Process: com.wabadaba.dziennik, PID: 18879
   java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.wabadaba.dziennik.test/com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner}: java.lang.ClassNotFoundException: Didn't find class "com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5730)
       at android.app.ActivityThread.-wrap1(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5728)
       at android.app.ActivityThread.-wrap1(Unknown Source:0) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
       at android.os.Handler.dispatchMessage(Handler.java:105) 
       at android.os.Looper.loop(Looper.java:164) 
       at android.app.ActivityThread.main(ActivityThread.java:6541) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Could this be related to #9 ?

Logo proposal for DEXOPENER

Hello, I'm a graphic designer and I like to collaborate with open source projects. I would like to design a logo for your Project I will be happy to collaborate with you :)

Not able to mock static class of third party library

I have tried to mock third party library static class in UI testing that worked very well in android above API 29 without using DexOpener.

For mock static class I have used Mockk Library . In Mockk they suggested to used dexopener library to mock final class before API 29.

When I configure this library and try to run test it fails and log the error not able to mock static class.

Cannot mock final classes declared on on pure Java / Kotlin modules

If you have a class defined on a pure Java or Kotlin library module (not Android) , let's say:core, then you write a UI test on your app module (the android application module) which uses that dependency, dexopener fails.

Cannot mock/spy class com.conversations.usecase.SendSyncServiceCommand
Mockito cannot mock/spy because :
- final class

Using DataBinding causes IllegalAccessError on Emulator API 19

  • OpenJDK 1.8.0_131

The steps to reproduce:

  1. Clone https://github.com/jaredsburrows/android-gif-example
  2. Apply the following patch in the project root
diff --git a/build.gradle b/build.gradle
index c45e8e0..ba57e81 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,6 +27,7 @@ buildscript {
 repositories {
   google()
   jcenter()
+  maven { url 'https://jitpack.io' }
 }
 
 apply from: rootProject.file("gradle/scan.gradle")
@@ -56,7 +57,7 @@ android {
     minSdkVersion rootProject.ext.lollipop ? 21 : rootProject.ext.minSdkVersion // Optimize build speed - build with minSdk 21 if using multidex
     targetSdkVersion rootProject.ext.targetSdkVersion
     testApplicationId "burrows.apps.example.gif.test"
-    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+    testInstrumentationRunner "com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner"
     resConfigs "en"                                                             // Optimize APK size - keep only english resource files for now
     vectorDrawables.useSupportLibrary = true                                    // Optimize APK size - use vector drawables
   }
@@ -184,6 +185,7 @@ dependencies {
   debugCompile deps.leakcanaryAndroid
   releaseCompile deps.leakcanaryAndroidNoOp
 
+  androidTestCompile 'com.github.tmurakami:dexopener:0.10.1'
   androidTestCompile deps.junit
   androidTestCompile deps.assertjCore
   androidTestCompile deps.mockitoKotlin, { exclude group: "net.bytebuddy" }     // DexMaker has it"s own MockMaker
  1. Start up the emulator whose API version is 19
  2. Run ./gradlew clean connectedDebugAndroidTest

Console log:

Starting 18 tests on Nexus_5_API_19(AVD) - 4.4.2

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testOnBindViewHolderOnAdapterItemClick[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testGetLocationShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testRemoveLocationObjectShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testGetItem[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testGetItemCountShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > onViewRecycled[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testOnCreateViewHolder[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testGetItemShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testAddObjectShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testRemoveLocationShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testGetListCountShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testAddLocationObjectShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testAddCollectionShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testClearShouldClearAdapter[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.adapter.GifAdapterTest > testRemoveObjectShouldReturnCorrectValues[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.adapter.GifAdapter.onCreateViewHolder(GifAdapter.kt:32)

burrows.apps.example.gif.presentation.main.MainActivityTest > testTrendingThenClickOpenDialog[Nexus_5_API_19(AVD) - 4.4.2] SKIPPED 

burrows.apps.example.gif.presentation.main.MainActivityTest > testTrendingResultsThenSearchThenBackToTrending[Nexus_5_API_19(AVD) - 4.4.2] FAILED 
        java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at burrows.apps.example.gif.presentation.main.MainActivity.onCreate(MainActivity.kt:26)
Tests on Nexus_5_API_19(AVD) - 4.4.2 failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'

FAILURE: Build failed with an exception.

IllegalArgumentException occurs when minSdkVersion is 24 or higher

ASMDEX does not support Dex format version 036 or later.

Logcat is here:

05-17 22:41:28.463  4394  4394 W System.err: java.lang.IllegalArgumentException: Unknown bytecode version
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.lowLevelUtils.BasicDexFileReader.readHeader(BasicDexFileReader.java:197)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.lowLevelUtils.BasicDexFileReader.parse(BasicDexFileReader.java:184)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.lowLevelUtils.DexFileReader.parse(DexFileReader.java:71)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.<init>(ApplicationReader.java:223)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.<init>(ApplicationReader.java:199)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.AndroidClassSource.newDelegate(AndroidClassSource.java:62)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.AndroidClassSource.getDelegate(AndroidClassSource.java:43)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.dexopener.AndroidClassSource.getClassFile(AndroidClassSource.java:37)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.classinjector.StealthClassLoader.findClass(StealthClassLoader.java:32)
05-17 22:41:28.463  4394  4394 W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
05-17 22:41:28.463  4394  4394 W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
05-17 22:41:28.463  4394  4394 W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.app.Instrumentation.newApplication(Instrumentation.java:992)
05-17 22:41:28.463  4394  4394 W System.err: 	at com.github.tmurakami.myapp.MyAndroidJUnitRunner.newApplication(MyAndroidJUnitRunner.kt:24)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5335)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.app.ActivityThread.-wrap2(ActivityThread.java)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
05-17 22:41:28.463  4394  4394 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:102)
05-17 22:41:28.464  4394  4394 W System.err: 	at android.os.Looper.loop(Looper.java:154)
05-17 22:41:28.464  4394  4394 W System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6077)
05-17 22:41:28.464  4394  4394 W System.err: 	at java.lang.reflect.Method.invoke(Native Method)
05-17 22:41:28.464  4394  4394 W System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
05-17 22:41:28.464  4394  4394 W System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

OutOfMemoryError when spinning up Instrumentation Tests

After creating my own Runner:

package com.target.location

import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import com.github.tmurakami.dexopener.DexOpener

class NewJUnitRunner : AndroidJUnitRunner() {
  @Throws(ClassNotFoundException::class, IllegalAccessException::class, InstantiationException::class)
  override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
    DexOpener.install(this) // Call me first!
    return super.newApplication(cl, className, context)
  }
}

I am seeing this exception when starting up the tests:

java.lang.OutOfMemoryError: Failed to allocate a 702649760 byte allocation with 6275072 free bytes and 341MB until OOM, max allowed footprint 50520112, growth limit 402653184
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.lowLevelUtils.DexFileReader.getAnnotationItemOffsetsFromAnnotationSetItem(DexFileReader.java:203)
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.readAndVisitAnnotations(ApplicationReader.java:1235)
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.visitMethods(ApplicationReader.java:777)
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.visitClass(ApplicationReader.java:614)
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:447)
at com.github.tmurakami.dexopener.repackaged.org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:328)
at com.github.tmurakami.dexopener.DexClassSource.getClassFile(DexClassSource.java:47)
at com.github.tmurakami.classinjector.ClassSources.getClassFile(ClassSources.java:44)
at com.github.tmurakami.dexopener.AndroidClassSource.getClassFile(AndroidClassSource.java:37)
at com.github.tmurakami.classinjector.StealthClassLoader.findClass(StealthClassLoader.java:32)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:282)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:275)
at dalvik.system.DexFile.loadClass(DexFile.java:264)
at com.github.tmurakami.classinjector.android.DexClassFile.toClass(DexClassFile.java:43)
at com.github.tmurakami.classinjector.StealthClassLoader.findClass(StealthClassLoader.java:40)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.reflect.Executable.getMethodReturnTypeInternal(Native Method)
at java.lang.reflect.Method.getReturnType(Method.java:141)
at java.lang.Class.getDeclaredMethods(Class.java:1880)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:54)
at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:65)
at org.junit.runners.model.TestClass.<init>(TestClass.java:57)
at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:43)
at androidx.test.runner.AndroidJUnit4.<init>(AndroidJUnit4.java:52)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.buildAndroidRunner(AndroidAnnotatedBuilder.java:71)
at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:48)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:153)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73)
at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:543)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:386)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)```

The test is pretty straight forward and is just using one `mock()` so I'm not sure off the top of my head what could be causing this. Perhaps it's even a machine specific issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.