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

后端 未结 10 1861
野的像风
野的像风 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:28

    When I created a new package, Studio created an ApplicationTest class. Using us.myname.mypackage as an example, the following directory structure was created:

    app/[myPackage]/src/androidTest/java/us/myname/mypackage/ApplicationTest.class
    

    Initially it worked out of the box. It quit working after I installed product flavors. I subsequently made the following changes to build.gradle:

    defaultConfig {
       ...
       testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
    

    some prefer

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    (With my current configuration, I have to use ...InstrumentationTestRunner when in debug, and AndroidJUnitRunner while using release build type.)

    The above configuration only works with the debug build type. If you wish to use it with release or with a custom build type, you can include the following in build.gradle:

    buildTypes {
         release {
             ...
         }
     debug {
         ...
     }
    }
    testBuildType "release"
    

    In the Build Variants tab on the lower left side of Studio, make sure you have Android Instrumentation Tests and the correct buildType selected.

提交回复
热议问题