您好,登錄后才能下訂單哦!
通過繼承InstrumentationTestRunner,就可以傳遞自定義參數(shù)到TestRunner。這里是傳遞port、packageName、activityName,其中port是用于在手機(jī)側(cè)啟動(dòng)一個(gè)TCP服務(wù)的端口,packageName和activityName是用于指定首個(gè)啟動(dòng)的activity的參數(shù)配置:
- import android.os.Bundle;
- import android.test.InstrumentationTestRunner;
- public class AthrunInstrumentationTestRunner extends InstrumentationTestRunner {
- private static String packageName = "com.taobao.fario";
- private static String activityName = "com.taobao.fario.MainActivity";
- private static String port = "1234";
- public static String getPort() {
- return port;
- }
- public static String getPackageName() {
- return packageName;
- }
- public static String getActivityName() {
- return activityName;
- }
- @Override
- public void onCreate(Bundle arguments) {
- if (arguments != null) {
- String port = arguments.getString("port");
- String packageName = arguments.getString("packageName");
- String activityName = arguments.getString("activityName");
- if (port != null) {
- AthrunInstrumentationTestRunner.port = port;
- }
- if (packageName != null) {
- AthrunInstrumentationTestRunner.packageName = packageName;
- }
- if (activityName != null) {
- AthrunInstrumentationTestRunner.activityName = activityName;
- }
- }
- super.onCreate(arguments);
- }
執(zhí)行命令變成:
- adb -s SH14MTJ01900 shell am instrument -w -e port 1234 -e class org.athrun.remoterunner.TravelTest#test org.athrun.remoterunner/org.athrun.instrumentation.AthrunInstrumentationTestRunner
在Testcase中如何使用傳入的packageName和activityName:
- public class TravelTest extends ActivityInstrumentationTestCase2 {
- private static String getPkgName() {
- String packageName = AthrunInstrumentationTestRunner.getPackageName();
- return packageName;
- }
- private static String getActivityClassStr() throws ClassNotFoundException {
- String activityName = AthrunInstrumentationTestRunner.getActivityName();
- return activityName;
- }
- public TravelTest() throws Exception {
- super(getPkgName(), getActivityClassStr());
- }
-e 是屬于擴(kuò)展參數(shù),使用這種方法是可以不斷擴(kuò)展的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。