61

So I'm trying our Android Studio and testing a project that worked in eclipse. I got everything compiling and the application will launch just fine, but I can't get my unit tests up and working. I eventually got them compiling by adding my applications lib folder as a dependency, but I don't think my run configuration is right because whenever I run my tests I get this error

Installing <packagename>
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/<packagename>"
pkg: /data/local/tmp/<packagename>
Success


Running tests
Test running started
Test running failed: Unable to find instrumentation info for: ComponentInfo{<packagename>/android.test.InstrumentationTestRunner}
Empty test suite.

Edit: To all new arrivals, the state of Android Studio has changed a lot since I initially posted this question, but many helpful people have continued to post their particular solution for this error. I'd advise sorting by active and checking out the newest answers first.

1
  • We'd need more information on the run config you use to try and run your tests, also a pic of your module structure maybe
    – Blundell
    May 17, 2013 at 19:42

15 Answers 15

62

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.

3
  • 3
    Selecting the specific instrumentation runner in Android Studio is the piece I was missing. Thanks! Jun 20, 2014 at 17:31
  • 3
    For Espresso: testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    – FireZenk
    Sep 21, 2015 at 14:08
  • if you use multidex see answers below: stackoverflow.com/a/37246190/1016367
    – Denis Nek
    Sep 29, 2016 at 11:59
20

In my case, the solution was:

  • View > Tool Windows > Build Variants
  • Select a *Debug variant
3
  • 2
    View > Tool Windows ... ? where is this? are you talking about Eclipse? Apr 29, 2014 at 9:39
  • 1
    Android Studio. Variants are Gradle build variants in Android Studio.
    – Lou Morda
    May 13, 2015 at 5:56
  • This no longer exists in Android Studio, plus no one uses eclipse
    – behelit
    Dec 16, 2016 at 4:48
18

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" … />
    
2
  • I had a custom InstrumentationTestRunner (Android Studio 0.9.1) and this solution helped me. When I added <instrumentation ... /> tag in the AndroidManifest the error stopped showing.
    – Ivan Kušt
    Nov 21, 2014 at 11:28
  • 4
    I assume this is the same as adding testInstrumentationRunner "android.test.InstrumentationTestRunner" to the defaultConfig in the app gradle file, for people who aren't in the 1980's and use Android Studio
    – behelit
    Dec 16, 2016 at 4:46
16

I solved this problem by changing

android.test.InstrumentationTestRunner 

into

com.android.test.runner.MultiDexTestRunner

in EditConfigurations -> Specific Instrumentation Runner (optional) tab.

Turns out, because my app is using MultiDex, I need to change test runner to MultiDexTestRunner as well.

UPDATE:

As @dan comment, InstrumentationTestRunner is deprecated use AndroidJUnitRunner instead.

1
4

In my case the Run/Debug Configurations were wrong.

One Solution:

  1. Go to Run/Debug Configurations

    Run -> Edit Configurations...

  2. Setup a Android-Test for your test class

  3. Select your Android test configuration on the left side
    or create a new one with the plus icon and name it e.g. ClassNameTest

  4. Select the module containing your test class. In the simplest case the test class is in your app module so select app.

  5. Select on the next row your test configuration. I use:

    • Class: to run all tests of one class.
  6. Choice your test class

  7. Finally configure your target device and select ok.

1
  • I had to select a JUnit type instead of Android test in order to run units. Apr 11, 2016 at 1:31
4

This only works in AndroidStudio Version < 2.3

In my case the wrong instrumentation runner was selected.

I fixed this by specifying the instrumentation runner in the Run/Debug Configuration of the test (see below). There you can select a runner from the list. 1]

You find the Run/Debug Configurations: Run -> Edit Configurations ...

2
  • 7
    This doesn't exist anymore (AS 2.3+)
    – behelit
    Dec 16, 2016 at 4:43
  • Any other suggestions for those of us using the latest?
    – worked
    Apr 24, 2017 at 0:17
1

It seams you have not good project structure.

  1. Open AndroidManifest.xml and check does it have

    <instrumentation android:name="android.test.InstrumentationTestRunner"
                         android:targetPackage="com.example.YourClass"
                         android:label="Tests for com.example.YourClass"/>
    

If NO do next:

  1. Reorganize your directory structure to the following one: (this is the recomendation from official source)
        MyProject/
              AndroidManifest.xml
              res/
                  ... (resources for main application)
              src/
                  ... (source code for main application) ...
              tests/
                  AndroidManifest.xml
                  res/
                      ... (resources for tests)
                  src/
                      ... (source code for tests)
  1. You see that you need to have inner tests module.
    For creating it in Idea IDE do next File -> New Module -> Test Module. After creating you can see one new AndroidManifest.xml. And it has instrumentation declaration inside.
1

I've got same problem as @Iuliia Ashomok and tried everything on the internet.

Still no luck.

After 2 days investigation, I found that the problem is created by the mobile phone. .V.

I originally use Xiaomi Mi4i as testing device(rooted) and tests could not be run. Of course, I got the error below.

Test running failed: Unable to find instrumentation info for: ComponentInfo{<packagename>/android.test.InstrumentationTestRunner}

However, when I use Sony Xperia Z3(No root), everything works well.

0

I once got this error. I use the sdk tools in CLI mode. And the error happened when i launch 'ant test' in the test project. I later notice that I didn't even build and install the test project before ! (with 'ant debug install') So you should have try to check your running configuration to see if the test project got effectively build before running the test. For the other case, Android Studio use Gradle. I don't know it well but try to check the Gradle settings for the project or the Gradle settings file.

0

For me the problem was having this dependency:

debugCompile 'com.android.support.test:rules:0.2'

After I removed it my tests were found and run again.

Note that I didn't get the "Unable to find instrumentation" message but a "No tests found" message.

0

It turned out to be a delay problem. It fixed automatically after I waited a while reading the Internet solutions. I recompiled the code, and it worked.

0

Since none of these answers helped me, I wanted to share my solution for anyone who is as desperate as I was. :)

Because of the testing libraries that I was using, I needed to enable multidex support by adding multiDexEnabled true to my Gradle build. I'm not sure I had multidex support fully implemented to begin with (the proper way of doing it has changed since I last implemented it) but ultimately, I didn't end up needing it and removing that line from my build fixed the error. My team at work has had a few testing issues related to enabling multidex support… in typical Android style.

0

In my case in same classes some test cases were picking correct test runner ( android.support.test.runner.AndroidJUnitRunner ) which was defined in build.gradle, and some test cases were picking up android.test.InstrumentationTestRunner, which was not defined at least in Manifest or build.gradle or edit configuration. Ideally it should have been resolved by Sync Project with Gralde option, though it didn't work.

At last I found wrong test runner defined against a method in .idea/workspace.xml, I changed it manually, and issue got resolved.

Generally we are not supposed to edit this Android Studio generated file, but for me it did worked as last option.

0

In my case, the issue was in device too. Other devices were working fine. Simple uninstall and reinstall fixed it.

0

This answer is going to explain the history issues and summarise all related settings.

Basically there are 3 possible places for instrumentation test runner configurations.

  1. In EditConfigurations -> General tab -> Specific Instrumentation Runner (optional)
    This is existing in Android Studio 2.2 and version before only, in latest version, it is removed already.

  2. In manifest file, the test runner is configured as below.

    < instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
           android:targetPackage="com.mytestapp.test"/>

Since "android.test.InstrumentationTestRunner" is deprecated in API level 24, this setting is also not necessary already, as long as you configure the runner in gradle file.
If you want to keep this setting, please make sure the runner name should match to the one you set in the gradle file, otherwise you will got this error also.

  1. In gradle file.
    This is the only recommended way if you use Android Studio v2.3 above.
    android {
    .......
        defaultConfig {  
            .......  
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"  
        }   
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.