17

I'm trying to run unit tests on the android platform in accordance with tutorial. Say, for example, I want to run tests for Email application. I open /apps/Email/tests/AndroidManifest.xml file, look for the <manifest> element, and look at the package attribute, which is com.android.email.tests, and in the <instrumentation> element I look at the android:name attribute, which is android.test.InstrumentationTestRunner. Now I open the console, and run

$ . build/envsetup.sh
$ lunch 1
$ adb shell am instrument -w com.android.email.tests/android.test.InstrumentationTestRunner

But that fails:

INSTRUMENTATION_STATUS: id=ActivityManagerService
android.util.AndroidException: INSTRUMENTATION_FAILED: com.android.email.tests/android.test.InstrumentationTestRunner
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.android.email.tests/android.test.InstrumentationTestRunner}

So.. What am I doing wrong?

9 Answers 9

8

Please run python development/testrunner/runtest.py email

and then you will see it works :).

Basically you do not have com.android.email.tests package installed.

You can see what is available for instrumentation

pm list instrumentation

And you should see

instrumentation:com.android.email.tests/android.test.InstrumentationTestRunner (target=com.android.email)

And when doing

pm list packages

package:com.android.email

package:com.android.email.tests

Sign up to request clarification or add additional context in comments.

2 Comments

Android doesn't use Python. Should be adb shell pm list instrumentation
Yes these are commands that you do in adb shell. Python is not in android but used to be in framework for testing android androidxref.com/4.2_r1/xref/development/testrunner/runtest.py
3

You may need to setup a test project with the android create test-project command first. Check this page on the Android Dev site: Testing In Other IDE's for more info. I've used this method to enable command line testing with ant.

Comments

2

What I actually forgot to do was building and installing that test packages onto my device/emulator. Discovered that after doing:

$ adb shell
# cd data/packages
# ls

And no com.android.email.tests package there.

Comments

1

My issue was this tag:

 <instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:label="Tests for app.under.test.package"
    android:targetPackage="app.under.test.package" />

Firstly I had the android:name attribute wrong then the target package wrong (above is the correct solution)

Comments

1

Test Package Not Installed on the Emulator

I had the exact same issue and realized that the test package hadn't been installed on the emulator, which is what @marekdef is saying.

Instead of using the command found in the generated test file, I used the following:

ant debug install test

*I had my test project in <project_home>/tests so the following command is what I ended up using from my project home directory:

(cd tests && ant debug install test;)

Hope that helps.

1 Comment

That worked for me, I was used for eclipse to create the test build, thanks!
0

I received the "Unable to find instrumentation info" error under this condition: I defined my test project with a src package name that was the same as that of the project-under-test. For example, the source for both projects was in package com.mycompany.android. This parallel-src-package setup worked fine in Eclipse, but on the emulator it very much appeared that the test apk was overwriting the app apk.

Fix: I changed the src packge of the test project to test.mycompany.android.

Note that, in either case, the Android manifest for the test project defines:

< manifest package="pkg-of-project-under-test" ...>

and

< instrumentation android:targetPackage="pkg-of-project-under-test" ...>

1 Comment

I just found that eclipse-Run does not care whether the manifest element defines package="pkg-of-project-under-test" (which is the value that eclipse inserts when it creates a new Android test project) or package="pkg-of-test-project". Why did I notice this? Well, eclipse-Build seems to care about that value. When I added the first Activity to my test project and edited the test manifest to describe it, eclipse started complaining that it couldn't find R when compiling my test activity. Changing the <manifest> package to pkg-of-test-project solved that problem.
0

For gradle user you can use the following tasks:

$ gradle :project:installDebug :project:installDebugAndroidTest

Comments

0

I have this run_all_test.sh script to run all unit and instrumented test:

#!/bin/bash
./gradlew --no-daemon clean test connectedCheck --stacktrace;
if [ $? -eq 0 ]
then
    echo "tests are successful"
else
    echo "tests FAILED"
    exit 1
fi

Explanation:

  • test -> execute all unit test

  • connectedCheck -> execute all instrumented test

You can start from here to customize it based on your needs following the documentation here: https://developer.android.com/studio/test/command-line

Comments

0

[Android test types]

To run all tests from Command Line using gradlew[About]

JUnit test (UnitTest suffix)

./gradlew test
./gradlew :<moduleName>:test<variantName>UnitTest

Instrument test(AndroidTest suffix)

./gradlew connectedAndroidTest
./gradlew :<moduleName>:connected<variantName>AndroidTest

If you want just to build tests and don't run them use assemble

//Unit
./gradlew :<moduleName>:assemble<variantName>UnitTest

//functional
./gradlew :<moduleName>:assemble<variantName>AndroidTest

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.