每个TestCase又包含若干个 Test(具体的test方法)。
如果假设com.android.foo是你的测试代码的包的根。
1.当执行以下命令时,会执行所有的TestCase的所有Test。测试的对象就是在Target Package中指定的包中的代码:
adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner
2.如果你想运行一个TestSuite,首先继承android.jar的junit.framework.TestSuite类,实现一个 TestSuite(比如叫com.android.foo.MyTestSuite),然后执行以下命令执行此TestSuite
adb shell am instrument -e class com.android.foo.MyTestSuite -w com.android.foo/android.test.InstrumentationTestRunner
其中的-e表示额外的参数,语法为-e [arg1] [value1] [arg2] [value2] …这里用到了class参数。
3.如果仅仅想运行一个TestCase(比如叫com.android.foo.MyTestCase),则用以下命令:
adb shell am instrument -e class com.android.foo.MyTestCase -w com.android.foo/android.test.InstrumentationTestRunner
4.如果仅仅想运行一个Test(比如就是上面MyTestCase的testFoo方法),很类似的,就这样写:
adb shell am instrument -e class com.android.foo.MyTestCase#testFoo -w com.android.foo/android.test.InstrumentationTestRunner