56

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

Running tests
Test running startedTest running failed: Unable to find instrumentation info for:
ComponentInfo{com.employeeappv2.employeeappv2.test/android.test.InstrumentationTestRunner}
Empty test suite.

I've been stuck on this for a while and the solutions I've seen online so far have not helped. My project structure is set up like this:

*Main Module -src *instrumentTest -java *main -java -manifest *build.gradle

My build.gradle file looks like this:

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 19
    versionCode 1
    versionName "2.1.0"
    testPackageName "login.test"
    testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-   rules.txt'
    }
}

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/scandit.zip')
compile project(':pullToRefresh')
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1+'
compile 'org.springframework.android:spring-android-rest-template:1.0.1+'
compile 'org.json:json:20090211'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.3.1'
compile 'com.android.support:support-v4:19.1.+'
compile 'com.mcxiaoke.volley:library:1.0.+@aar'
androidTestCompile 'junit:junit:3.8'
}

Do you need to have a separate manifest for your tests directory? If so what would that look like?

Edit: I tried adding a manifest to my instrumentTest directory with no luck. Note that I could not get IntelliJ to resolve the targetPackage name, so it appears red.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.employeeappv2.employeeappv2.src.instrumentTest"
      android:versionCode="1"
      android:versionName="1.0.0">
<application>
    <uses-library android:name="android.test.runner" />
</application>
<instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.employeeappv2.employeeappv2.src.main"/>
</manifest>
njthoma
  • 785
  • 3
  • 7
  • 11

10 Answers10

30

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)

Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
25

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.

Liuting
  • 1,098
  • 17
  • 35
  • 1
    The first step is Optional, the IDE can figure it out by itself. Second step is the key, I had forgotten Unit Tests On. – Radu Oct 26 '15 at 12:05
  • 5
    The second step is obsolete in the newest versions of Android Studio. – nasch May 09 '16 at 15:17
  • 16
    I only see 'Android Instrumented Tests', and in that screen there are no options for instrumentation runner. Please delete your answer – behelit Dec 16 '16 at 04:37
21

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.

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
VikingGlen
  • 1,705
  • 18
  • 18
12

I had to do a combination of VikingGlen's answer, Liuting's answer, and this answer. This answer works for Android Studio version 2.1.

  1. Run -> Edit Configurations... -> General -> Specific instrumentation runner (optional): "android.support.test.runner.AndroidJUnitRunner"

  2. In build.gradle (the one with all your dependencies), put this:

defaultConfig {
   testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} 

Then it could run tests of this type:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void login() {
        //Open Drawer to click on navigation.
        onView(withId(R.id.drawer_layout))
                .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
                .perform(open()); // Open Drawer
    }
}
Dhaval Kansara
  • 3,478
  • 5
  • 22
  • 50
Rock Lee
  • 9,146
  • 10
  • 55
  • 88
11

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.

LEO
  • 2,572
  • 1
  • 26
  • 31
1

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.

njthoma
  • 785
  • 3
  • 7
  • 11
  • 4
    Im getting the error now in AS 0.8.8. I created my androidTest folder by dragging/droping it from a AS "New Project" where it is automatically generated...So it appears that method isnt working...Do you know how to properly create an androidTest folder in an existing project that didnt originally have one? – Tim Boland Aug 30 '14 at 16:41
  • I am having a similar issue. Any resolution? (And the name is just a massive coincidence). – timbo Feb 02 '15 at 13:46
  • Sorry it has been a good while since I've done any Android work I don't think I will be of much help anymore – njthoma Feb 05 '15 at 02:49
  • @TimBoland create a new folder called 'androidTest' under 'app/src'. i.e. this folder should be a sibling to your 'main' folder. – Nicolás Carrasco-Stevenson Jan 19 '16 at 19:22
1

I had this problem and fixed it by going to Run -> Edit Configurations -> Green '+' button at the top left -> JUnit

From there, set the 'use the classpath mod...' to 'app' (or your default app name, which is the one that appears to the left of the run (play button) when you run the app)

Finally, put your test class name in the 'class:' textbox. Click apply and okay.

At this point, if the test class doesn't have other errors, it should work.

dbep
  • 647
  • 6
  • 20
1

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.

Agnit
  • 141
  • 7
  • For some reason, having MultiDexTestRunner will not run tests with @RunWith(AndroidJUnit4.class) when I run connectedDebugAndroidTest or createDebugCoverageReport. However tests pass when I run individual tests from studio. Any support on how to fix? – Ramya K Sharma May 31 '17 at 17:12
  • MultiDexTestRunner is now deprecated. – 最白目 Jun 08 '17 at 11:44
1

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.

Sababado
  • 2,524
  • 5
  • 33
  • 51
-1

The solution for my problem is to change the method name from

@Test
public void test() {
    ...
}

to

@Test
public void testSomething() {
    ...
}

Hope it helps someone.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Dino Tw
  • 3,167
  • 4
  • 34
  • 48