Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 609
AJD Avatar asked May 16 '13 15:05

AJD


5 Answers

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.

like image 142
thoutbeckers Avatar answered Nov 10 '22 23:11

thoutbeckers


In my case, the solution was:

  • View > Tool Windows > Build Variants
  • Select a *Debug variant
like image 36
Matt McClure Avatar answered Nov 10 '22 23:11

Matt McClure


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" … />
    
like image 40
BenL Avatar answered Nov 10 '22 22:11

BenL


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.

like image 28
aldok Avatar answered Nov 10 '22 23:11

aldok


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.

like image 4
auerc89 Avatar answered Nov 11 '22 00:11

auerc89