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

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

    I am using Android Studio 1.1 and the following steps solved this issue for me:

    1. In Run - Edit Configurations - Android Tests
      Specify instrumentation runner as android.test.InstrumentationTestRunner

    2. Then in the "Build variants" tool window (on the left), change the test artifact to Android Instrumentation Tests.

    No testInstrumentationRunner required in build.gradle and no instrumentation tag required in manifest file.

    0 讨论(0)
  • 2021-02-01 01:28

    I had the same error when I tried adding multiDexEnabled true to build.gradle.

    I'm adding my experience here, because this is one of the first Google hits when searching with the ... Unable to find ... ComponentInfo ... error message.

    In my case adding testInstrumentationRunner like here did the trick:

    ...
    android {
        ...
        defaultConfig {
            ...
            testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
        }
    }
    

    (I have com.android.tools.build:gradle:1.5.0)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-01 01:28

    So the main problem was that when I created an androidTest folder under /src/, it wasn't being picked up by IntelliJ as a source folder for testing (java subdirectory should turn green). I was using IntelliJ 13.0.3 and after upgrading to 13.1.3, all of my troubles went away.

    *Note: do not try to add a manifest to your androidTest folder, the Gradle docs specifically state that the manifest should be auto-generated when you create the androidTest folder. The problem for me was that the file wasn't being generated as androidTest wasn't being recognized by IntelliJ/Gradle, thus throwing the no instrumentation error.

    0 讨论(0)
  • 2021-02-01 01:29

    Make sure the app has been uninstalled for all users.

    Go to settings -> apps (all apps) -> If your app is there then tap on it -> menu -> uninstall for all users.

    My issue was that the app was at one point uninstalled, however still on the device; meaning it was not uninstalled for all users. (Another issue, not sure how to resolve. I'm the only user on my device)

    Because of this, the app wouldn't re-install, and the test suite had nothing to run against.

    0 讨论(0)
  • 2021-02-01 01:34

    For what it's worth, AS 2.3 got hung up when i created a custom test runner after using the regular test runner. I got the same error as posted in the question.

    Deleting the Debug Configurations for ALL Android Instrumented Tests and rebuilding fixed it. I believe the problem lied in the fact you no longer can choose a custom runner in the Debug Configurations because it's most likely built in via gradle.

    0 讨论(0)
提交回复
热议问题