Java 从命令行启动android测试时的自定义参数
我可以从命令行启动Android应用程序Junit/Robotium测试,如下所示:Java 从命令行启动android测试时的自定义参数,java,android,variables,command-line-arguments,robotium,Java,Android,Variables,Command Line Arguments,Robotium,我可以从命令行启动Android应用程序Junit/Robotium测试,如下所示: adb shell am instrument -w com.myapp.client.test/android.test.InstrumentationTestRunner adb shell am instrument -w -e size medium com.me.client.test/android.test.InstrumentationTestRunner adb shell am inst
adb shell am instrument -w com.myapp.client.test/android.test.InstrumentationTestRunner
adb shell am instrument -w -e size medium com.me.client.test/android.test.InstrumentationTestRunner
adb shell am instrument -w -e size large com.me.client.test/android.test.InstrumentationTestRunner
但是,我希望以某种方式包含一个自定义参数,该参数允许我指定测试是在“纵向”模式还是在“横向”模式下运行
我怎样才能:
谢谢我对此提出了一个破解方案。看起来这里没有干净的解决方案 我的技巧是利用可以附加到测试的“小”、“中”和“大”属性
@MediumTest
public void testPortraitTest1() throws Exception{
this.MetaDataTest(Solo.PORTRAIT);
}
@LargeTest
public void testLanscapeTest1() throws Exception{
this.MetaDataTest(Solo.LANDSCAPE);
}
然后,您可以使用批处理文件先调用中等测试,然后调用大型测试,如下所示:
adb shell am instrument -w com.myapp.client.test/android.test.InstrumentationTestRunner
adb shell am instrument -w -e size medium com.me.client.test/android.test.InstrumentationTestRunner
adb shell am instrument -w -e size large com.me.client.test/android.test.InstrumentationTestRunner
谷歌没有让这变得更容易,真是太遗憾了。您可以扩展Android Instrumentation runner并重写oncreate()方法,从命令行获取自定义参数。在执行测试用例时使用定制的检测运行程序
public class CustomInstrumentationRunner extends android.test.InstrumentationTestRunner{
@Override
public void onCreate(Bundle arguments) {
//process you parameters here.
super.onCreate(arguments);
}
@Override
public void onStart() {
try {
logger = CustomLogger.GetLogger();
} catch (Exception e) {
throw new RuntimeException(e);
}
super.onStart();
}
我这样做的方式是:
在运行测试之前,我在SD卡中保存了一个文本文件\
当测试开始时,在设置中,我解析文本文件的每一行并提取键/值
arg1=valueX
arg2=valueY您可以使用
adb shell am insrument -e <NAME> <VALUE> <package/runner>