48

I am trying to stand up espresso tests but I keep getting this error:

INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.mikeestrada.test/android.test.InstrumentationTestRunner}

It worked once, but I can't get the reports to recreate correctly. They are just blank, didn't test anything. I've tried a plethora of commands including

adb shell am instrument -w -r com.mikeestrada.test/android.test.InstrumentationTestRunner

and

adb shell am instrument -w -r   com.mikeestrada.test/com.google.android.apps.common.testing.testrunner.GoogleInstrumentation TestRunner

Here are my code snippets:

AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.myapplication"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="7"
            android:targetSdkVersion="19" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.myapplication.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
                <instrumentationandroid:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"                   
    android:targetPackage="com.mikeestrada.test"/>

TestStartScreen.java

    package com.mikeestrada.test;

    import android.test.ActivityInstrumentationTestCase2;
    import android.test.ActivityUnitTestCase;
    import android.test.AndroidTestCase;
    import android.test.suitebuilder.annotation.LargeTest;
    import android.view.View;

    import com.example.myapplication.MainActivity;
    import com.example.myapplication.R;
    import com.google.android.apps.common.testing.ui.espresso.Espresso;
    import com.google.android.apps.common.testing.ui.espresso.ViewAssertion;
    import com.google.android.apps.common.testing.ui.espresso.ViewInteraction;
    import com.google.android.apps.common.testing.ui.espresso.action.ViewActions;
    import com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions;
    import com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers;

    import junit.framework.Assert;
    import org.hamcrest.Matcher;


    public class TestStartScreen extends ActivityInstrumentationTestCase2<MainActivity> {

        public TestStartScreen() {
            super(MainActivity.class);
        }

        @LargeTest
        public void testHelloWorld(final Matcher<View> viewMatcher) {
            // Find
            //ViewInteraction button1 = onView(ViewMatchers.withId(R.id.button1)); // Find the button
            ViewInteraction helloWorldText = Espresso.onView(ViewMatchers.withText("Hello world!")); // Find the text

            // Action
            //button1.perform(ViewActions.click()); // Click the button
            helloWorldText.perform(ViewActions.typeText("Bye World!"));
            Espresso.onView(ViewMatchers.withText(R.id.withText));

            // Check
            helloWorldText.check(ViewAssertions.matches((ViewMatchers.isDisplayed())));  // Hello world text is hidden

            //Espresso.onView(withId(R.id.my_view)).check(matches(withText("Hello  world!")));
        }
    }

build.gradle

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    instrumentTestCompile files('libs/espresso-1.1-bundled.jar')
}
android {
    defaultConfig {
        testInstrumentationRunner     "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }
}
task wrapper (type: Wrapper) {
    gradlerVersion = '1.9'
}

If it means anything - the attributes of <instrumentation> in the manifest are colored red as if IntelliJ does not recognize them.

Any help is great, thanks!

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
mikeestrada67
  • 491
  • 1
  • 4
  • 4
  • Could you post your test AndroidManifest.xml? – Bolhoso Jan 27 '14 at 00:03
  • Ops, sorry about that, now I see the tag ;) What called my attention is that you have an activity declared in your section of your AndroidManifest. I've never seen a test app declare an activity. Try removing that and check if your tests run as you deserve. – Bolhoso Jan 28 '14 at 01:04
  • maybe this will be of help: http://stackoverflow.com/questions/14269687/android-util-androidexception-instrumentation-failed – gsaslis Apr 18 '14 at 10:21

7 Answers7

111

You need to check which instrumentation packages have been installed on your device:

 adb shell pm list instrumentation

Then verify whether com.mikeestrada.test is actually listed there.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
  • 19
    and if it's not? – behelit Apr 12 '16 at 07:59
  • @behelit Then you cannot perform instrumentation testing on it. – IgorGanapolsky Apr 12 '16 at 12:43
  • @dan When you say ~"**nothing works**", what error specifically are you getting? – IgorGanapolsky Mar 14 '17 at 15:09
  • How should instrumentation packages be installed? – Julius May 26 '17 at 08:05
  • @Julsteri It is declared in your build.gradle. When you run the tests, instrumentation for them will automatically be installed. – IgorGanapolsky May 26 '17 at 12:58
  • @IgorGanapolsky I have declared a dedicated runner for Cucumber in build.gradle, but it is not listed in `pm list instrumentation`. – Julius May 29 '17 at 11:03
  • @Julsteri You need this in your build.gradle as well: **testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"** – IgorGanapolsky May 30 '17 at 13:15
  • @Julsteri I wasn't aware that a specific app id needs to be declared. That is not mentioned in this document: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html. Glad you got it working though... – IgorGanapolsky May 30 '17 at 13:28
  • 1
    I think I read somewhere that the app id's should automatically be configured so that they would be unique at runtime. But changing it manually (appended ".test") was the only way I was able to get my tests running. I don't know why. – Julius May 31 '17 at 09:12
  • 1
    Sorry! I am unable to verify that my application listed there with the given command "adb shell pm list instrumentation". If I am using "adb shell "pm list packages"|cut -f 2 -d ":"" Its displaying my application . – Vijay Mar 06 '18 at 10:06
14

If the instrumentation package is missing install it with the following command:

$ gradle :{$project}:installDebugAndroidTest

gradle task showing location of installDebugAndroidTest

korosmatick
  • 579
  • 4
  • 8
6

Looking at your build.gradle file, the problem is actually that you don't have the following configuration in the defaultConfig section:

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

Espresso requires GoogleInstrumentationTestRunner in order to work.

Also with a gradle build system you shouldn't need an AndroidManifest.xml for the test project because it is auto generated.

Dmitry Ginzburg
  • 7,391
  • 2
  • 37
  • 48
Marc Thomas
  • 393
  • 1
  • 3
  • 16
2

To correctly run instrumentation testing, follow these instructions:

  1. Install the base package on device/emulator. For example if you want to test devDebug {flavorBuildType} combination, execute ./gradlew installDevDebug. Replace devDebug string with flavor and buildType you have in your project.

  2. Install the test package on device/emulator. If you installed devDebug now execute ./gradlew installDevDebugAndroidTest, by default this will install the base package adding the .test suffix

  3. Verify instrumentation is correctly installed, running adb shell pm list instrumentation it should print a line with your test package and the available runner, something like: androidx.test.runner.AndroidJUnitRunner

  4. Launch the instrumentation test. For example if you want to test a single test class from your package, you can go with this: adb shell am instrument -w -e class com.your.base.package.MyClassTest com.your.base.package.test/androidx.test.runner.AndroidJUnitRunner. Check the doc here for all the available options

  5. Optional: After tests have been completed you can uninstall the packages with ./gradlew uninstallDevDebug uninstallDevDebugAndroidTest

MatPag
  • 41,742
  • 14
  • 105
  • 114
1

https://developer.android.com/studio/test/command-line

Looks like you need to make sure you app and test apks are installed.

ether_joe
  • 1,068
  • 1
  • 13
  • 32
0

Also, looks like yours app package is com.mikeestrada. So in AndroidManifest set android:targetPackage as android:targetPackage="com.mikeestrada".

I hope this will help.

PLNech
  • 3,087
  • 1
  • 23
  • 52
paynd
  • 813
  • 8
  • 16
0

The issue is that you are missing a space:

instrumentationandroid:name

should be

instrumentation android:name
Frank Bryce
  • 8,076
  • 4
  • 38
  • 56