Test running failed: Unable to find instrumentation info for: ComponentInfo{} — error trying to test in IntelliJ with Gradle

后端 未结 10 1860
野的像风
野的像风 2021-02-01 01:14

Everytime I try to run my tests the console says this:

Running tests
Test running startedTest running failed: Unable to find instrumentation info for:
ComponentI         


        
10条回答
  •  温柔的废话
    2021-02-01 01:44

    This is what I noticed in my project, in my app(main) module build.gradle I had the following buildType configuration

    buildTypes {
            debug {
                multiDexEnabled true
            }
    
            mock {
                initWith(buildTypes.debug)
            }
        }
    testBuildType "mock"
    

    When I used AndroidJUnitRunner as the test runner(both from Android Studio) and as testInstrumentationRunner in build.gradle, tests ran without hitch.

    In a submodule that had multiDexEnabled true as defaultConfig

    defaultConfig {
        multiDexEnabled true
        ....
    }
    

    I ran into the problem of

    Test running startedTest running failed: Unable to find instrumentation info for:{mypackage.x.y/android.support.test.runner.AndroidJUnitRunner"}
    

    when I specified AndroidJUnitRunner in IDE and the submodule build.gradle. And this was fixed by specifying MultiDexTestRunner as the test runner in IDE/build.gradle.

    To summarize, Use MultiDexTestRunner to run tests when multiDexEnabled true is specified in build.gradle, else use AndroidJUnitRunner as the test runner.

提交回复
热议问题