How to add testInstrumentation environment variable for firebase testlab?

旧时模样 提交于 2021-02-18 18:57:43

问题


If i am going to run espresso test locally and pass enviroment variable i can do this by adding

defaultConfig {
 testInstrumentationRunnerArgument 'USERNAME' 'David'
}

in build.gradle file

then i can call this variable by

InstrumentationRegistry.getArguments().getString("USERNAME")

but when i run this on firebase testlab instrumentationrunner argument are not working


回答1:


This is not supported in Test Lab.

If you really need to do this, there's a workaround by overriding the test runner and using the test runner "environment variables" to pass in those key-value pairs.

Override the test runner:

public class MyTestRunner extends AndroidJUnitRunner {

    public static String USERNAME;

    @Override
    public void onCreate(Bundle arguments) {
        super.onCreate(arguments);

        USERNAME = arguments.getString("USERNAME");
    }
}

Use MyTestRunner in your build.gradle file:

defaultConfig {
    testInstrumentationRunner "com.example.myapp.MyTestRunner"
}

Start your test run in Firebase using the gcloud command-line app. This is where you pass in your arguments:

gcloud firebase test android run \
    --type instrumentation \
    --app debug/app-debug.apk \
    --test androidTest/debug/app-debug-androidTest.apk \
    --environment-variables "USERNAME=david" \
    --device model=walleye,version=28


来源:https://stackoverflow.com/questions/53295135/how-to-add-testinstrumentation-environment-variable-for-firebase-testlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!