2011-11-21 67 views
0

我有一個測試用例文件,它包含大約20個擴展了ActivityInstrumentationTestCase2的方法(測試用例)。我需要寫這將調用僅選擇的測試方法一套房,我知道在JUnit中有被執行機器人測試套件問題

suite.addTest(new AllTestCases("testcase1")); 

它接受的方法一種方法是不是也有類似的方式做的東西,在Android的robotium?如果是的話,請幫我解決這個問題。謝謝。

回答

1

您不能撥打電話,如new AllTestCases("testcase1");,因爲所有與Android相關的測試類都從AndroidTestCaseInstrumentationTestCase繼承,並且這兩個類都沒有公開將字符串作爲參數的構造函數。

你可以看看android.test.suitebuilder.TestSuiteBuilder,但即使這個類不允許運行單個測試方法,它也會接受包級別的測試。

你可能有一些運氣使用Android的測試註釋實現自己的目標,如@SmallTest@MediumTest@LargeTest等,這些可以讓你使用follwing命令只針對指定的註解的方法:

adb shell am instrument -w -e size <small|medium|large> com.youproject.test/android.test.InstrumentationTestRunner 

最後,它可能直接從eclipse中針對單個測試方法或類。

0

您可以用「-e」參數以編程方式運行單個測試用例到「adb shell am instrument」命令。例如,對於'com.foo.bar.FooTest'中的'testFoo()'方法,您可以運行:

adb shell am instrument -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

1

要直接從命令行運行單個測試用例:

adb shell am instrument -w -e class < 試驗類與 - 包名稱># < 試驗方法名> < 包名稱 - 中試驗應用>/ < 儀表-名稱定義的多功能清單>

示例:

adb shell am instrument -w -e class com.myapp.test.ActivityFragmentTest#testLogin com.myapp.test/android.test.InstrumentationTestRunner