Android Studio import existing unit tests "Unable to find instrumentation info"

Solution 1:

If you have a testInstrumentationRunner defined in your build.gradle such as this:

android {
    defaultConfig {
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"

make sure that in the run configuration window you use the exact same "Specific instrumentation runner" in your Android Studio / IntelliJ run configuration for your test.

Solution 2:

In my case, the solution was:

  • View > Tool Windows > Build Variants
  • Select a *Debug variant

Solution 3:

Explanation and solution

This error "Unable to find instrumentation" appears if targetPackage declared in the manifest of the test application is different from the package declared in the manifest of the application being tested:

  • Application being tested:

    <manifest package="com.example.appbeingtested" … >
    
  • Test application :

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.example.appbeingtested" … />