AndroidX : No instrumentation registered! Must run under a registering instrumentation

后端 未结 6 1695
长情又很酷
长情又很酷 2020-12-09 14:26

I\'m trying to run a local unit test that depends on the context, and was following this guide: https://developer.android.com/training/testing/unit-testing/local-unit-tests#

6条回答
  •  一向
    一向 (楼主)
    2020-12-09 15:21

    I had similar error and was struggling a lot to fix it. My problem was that I was mixing AndroidJUnit4, InstrumentationRegistry, ApplicationProvider and AndroidJUnitRunnerversions / packages. Make sure they all are of the same generation. These are the classes that made it all run for me:

    • androidx.test.runner.AndroidJUnitRunner
    • androidx.test.platform.app.InstrumentationRegistry
    • androidx.test.ext.junit.runners.AndroidJUnit4
    • androidx.test.core.app.ApplicationProvider

    for these I needed the following in the dependencies part of my build.gradle

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation "com.android.support:support-annotations:27.1.1"
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    

    And of course the correct

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    in my defaultConfig of the build.gradle

提交回复
热议问题