我有一个包含大约 20 个方法(测试用例)的测试用例文件,它扩展了 ActivityInstrumentationTestCase2。我需要编写一个仅调用选定测试用例方法的套件,我知道在 junit 中有一个方法可以接受要执行的方法
suite.addTest( new AllTestCases("testcase1"));
有没有类似的方法在 android robotium 中做事?如果是,请帮助我解决此问题。谢谢。
要直接从命令行运行单个测试用例:
adb shell am instrument -w -e class
< Test-Class-With-Package-Name > #
< Test-Method-Name >< Package-Name-Of-Test-App > /
< Instrumentation-Name-Defined-In-Manifest >
例子:
adb shell am instrument -w -e class com.myapp.test.ActivityFragmentTest#testLogin com.myapp.test/android.test.InstrumentationTestRunner
您不能进行这样的调用,new AllTestCases("testcase1");
因为所有与 Android 相关的测试类都继承自其中任何一个,AndroidTestCase
或者InstrumentationTestCase
这些类都不公开将字符串作为参数的构造函数。
你可以看一下,android.test.suitebuilder.TestSuiteBuilder
但即使这个类也不允许运行单独的测试方法,它接受包级别的测试。
通过使用 Android 测试注解(例如 、 等),您可能会有一些运气来实现您的目标@SmallTest
。@MediumTest
这些@LargeTest
将允许您使用以下命令仅针对指定的注解方法:
adb shell am instrument -w -e size <small|medium|large> com.youproject.test/android.test.InstrumentationTestRunner
最后,它可以直接从 Eclipse 中针对单个测试方法或类。
您可以使用“adb shell am instrument”命令的“-e”参数以编程方式运行单个测试用例。例如,对于“com.foo.bar.FooTest”中的方法“testFoo()”,您可以运行:
adb shell am 仪器 -w \ -e "class com.foo.bar.FooTest#testFoo" \ com.foo.bar.test/android.test.InstrumentationTestRunner
http://developer.android.com/guide/developing/testing/testing_otheride.html