Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 515
njthoma Avatar asked Jun 02 '14 19:06

njthoma


3 Answers

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)

like image 119
Peter Lamberg Avatar answered Nov 03 '22 07:11

Peter Lamberg


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.

like image 25
Liuting Avatar answered Nov 03 '22 06:11

Liuting


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.

like image 20
VikingGlen Avatar answered Nov 03 '22 05:11

VikingGlen