How to pass an argument to an AndroidTestCase?

前端 未结 3 2153
一向
一向 2020-12-31 18:09

I\'ve implemented an Instrumentation and an AndroidTestCase.

For my tests I need to connect to an external WIFI device. I want the testers to be able to specify an S

3条回答
  •  执笔经年
    2020-12-31 19:02

    Found a solution.

    I made my test-runner inherit from InstrumentationTestRunner and took the extra data in onCreate():

    public class MyTestRunner extends InstrumentationTestRunner {
    
        public static String BAR;
    
        public void onCreate(Bundle arguments) {
    
            if (null != arguments) {    
                BAR = (String) arguments.get("foo"));
            }    
            super.onCreate(arguments);
        }
    }
    

    I added to Android.mk:

    LOCAL_JAVA_LIBRARIES := android.test.runner
    

    And to AndroidManifest.xml:

    
    

    Ran it using this command line:

    adb shell am instrument -w -e foo the_value_of_bar com.example/com.example.MyTestRunner
    

    I was able to get the 'foo' parameter from the command line and use BAR in my AndroidTestCase.

提交回复
热议问题