mikeestrada67
mikeestrada67

Reputation: 501

Error=Unable to find instrumentation info for: ComponentInfo{ }

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!

Upvotes: 49

Views: 38597

Answers (7)

MatPag
MatPag

Reputation: 44813

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

Upvotes: 3

ether_joe
ether_joe

Reputation: 1108

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

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

Upvotes: 1

korosmatick
korosmatick

Reputation: 579

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

$ gradle :{$project}:installDebugAndroidTest

gradle task showing location of installDebugAndroidTest

Upvotes: 14

Omar Madbouli
Omar Madbouli

Reputation: 1

The issue is that you are missing a space:

instrumentationandroid:name

should be

instrumentation android:name

Upvotes: 0

paynd
paynd

Reputation: 813

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.

Upvotes: 0

Marc Thomas
Marc Thomas

Reputation: 393

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.

Upvotes: 6

IgorGanapolsky
IgorGanapolsky

Reputation: 26821

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.

Upvotes: 115

Related Questions