views:

84

answers:

3

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?

A: 

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.

Marc Bernstein
A: 

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.

folone
A: 

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" ...>

cdhabecker
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.
cdhabecker