如何为 firebase testlab 添加 testInstrumentation 环境变量?

How to add testInstrumentation environment variable for firebase testlab?

如果我要 运行 在本地进行 espresso 测试并传递环境变量 我可以通过 添加

defaultConfig {
 testInstrumentationRunnerArgument 'USERNAME' 'David'
}

build.gradle文件中

然后我可以通过

调用这个变量
InstrumentationRegistry.getArguments().getString("USERNAME")

但是当我 运行 这个在 firebase 测试实验室 工具运行ner 参数不起作用

测试实验室不支持此功能。

如果您真的需要这样做,可以通过覆盖测试 运行ner 并使用测试 运行ner "environment variables" 传递这些键值对来解决。

覆盖测试 运行ner:

public class MyTestRunner extends AndroidJUnitRunner {

    public static String USERNAME;

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

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

在您的 build.gradle 文件中使用 MyTestRunner

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

使用 gcloud 命令行应用在 Firebase 中开始测试 运行。这是您传递参数的地方:

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