Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从命令行启动android测试时的自定义参数_Java_Android_Variables_Command Line Arguments_Robotium - Fatal编程技术网

Java 从命令行启动android测试时的自定义参数

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

我可以从命令行启动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 instrument -w -e size large com.me.client.test/android.test.InstrumentationTestRunner
但是,我希望以某种方式包含一个自定义参数,该参数允许我指定测试是在“纵向”模式还是在“横向”模式下运行

我怎样才能:

  • 是否在命令行命令中指定该自定义参数

  • 如何在Java代码中访问该自定义参数的值


  • 谢谢

    我对此提出了一个破解方案。看起来这里没有干净的解决方案

    我的技巧是利用可以附加到测试的“小”、“中”和“大”属性

       @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>