Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running android unit tests from the command line?

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?

like image 855
George Avatar asked Jul 21 '10 12:07

George


People also ask

How do I run unit test on Android?

To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .

How do I run a Gradle test in CMD?

Use the command ./gradlew test to run all tests.

How run all test cases in Android?

Right click on a test class name in the editor (or a filename in the project explorer) to run all tests in a single class. The default keyboard shortcut for this is Ctrl+Shift+F10 on Linux. I suggest you map it to something easier to remember like Ctrl+Alt+R.


2 Answers

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

like image 97
marekdef Avatar answered Nov 04 '22 12:11

marekdef


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.

like image 30
Marc Bernstein Avatar answered Nov 04 '22 12:11

Marc Bernstein