问题描述
如果我要在本地运行espresso测试并传递环境变量我可以做到这一点添加
If i am going to run espresso test locally and pass enviroment variablei can do this byadding
defaultConfig {
testInstrumentationRunnerArgument 'USERNAME' 'David'
}
在 build.gradle文件
然后我可以通过
InstrumentationRegistry.getArguments().getString("USERNAME")
但是当我在firebase testlab上运行它时instrumentationrunner参数不起作用
but when i run this on firebase testlabinstrumentationrunner 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环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!