我有一个包含大约20个方法(测试用例)的测试用例文件,它扩展了ActivityInstrumentationTestCase2。我需要编写一个套件,它将只调用选定的测试用例方法,我知道在junit中有一个方法接受要执行的方法。
suite.addTest( new AllTestCases("testcase1"));在android robotium中有没有类似的方法?如果是,请帮我解决这个问题。谢谢。
发布于 2012-05-08 08:03:02
您不能进行像new AllTestCases("testcase1");这样的调用,因为所有与Android相关的测试类都继承自AndroidTestCase或InstrumentationTestCase,并且这两个类都没有公开以字符串作为参数的构造函数。
您可以看看android.test.suitebuilder.TestSuiteBuilder,但即使这个类不允许运行单独的测试方法,它也接受包级别的测试。
你可以通过使用@SmallTest,@MediumTest,@LargeTest等安卓测试注解来实现你的目标。这些注解允许你使用下面的命令只针对指定的带注解的方法:
adb shell am instrument -w -e size <small|medium|large> com.youproject.test/android.test.InstrumentationTestRunner最后,可以直接从eclipse中针对各个测试方法或类进行测试。
发布于 2014-08-25 21:56:56
要直接从命令行运行单个测试用例:
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
发布于 2012-06-01 08:43:12
您可以使用"adb shell am instrument“命令的"-e”参数以编程方式运行各个测试用例。例如,对于'com.foo.bar.FooTest‘中的方法'testFoo()’,您可以运行:
com.foo.bar.test/android.test.InstrumentationTestRunner shell am instrument -w \ -e "class com.foo.bar.FooTest#testFoo“\ adb shell am instrument
http://developer.android.com/guide/developing/testing/testing_otheride.html
https://stackoverflow.com/questions/8208713
复制相似问题