如何为Firebase TestLab添加testInstrumentation环境变量? [英] How to add testInstrumentation environment variable for firebase testlab?

查看:56
本文介绍了如何为Firebase TestLab添加testInstrumentation环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要在本地运行espresso测试并传递环境变量我可以做到这一点添加

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

defaultConfig {
 testInstrumentationRunnerArgument 'USERNAME' 'David'
}

build.gradle文件

然后我可以通过

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

但是当我在firebase testlab上运行它时instrumentationrunner参数不起作用

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

推荐答案

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

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.

覆盖测试运行器:

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中开始测试运行.这是您传递参数的地方:

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

这篇关于如何为Firebase TestLab添加testInstrumentation环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆