如果我要在本地运行espresso测试并通过环境变量我可以通过添加
defaultConfig {
testInstrumentationRunnerArgument 'USERNAME' 'David'
}
在build.gradle文件中
那么我可以通过调用这个变量
InstrumentationRegistry.getArguments().getString("USERNAME")
但当我在firebase测试实验室上运行时instrumentationrunner参数不起作用
这在测试实验室中不受支持。
如果您真的需要这样做,有一个变通方法,即覆盖测试运行程序并使用测试运行程序"环境变量"传入这些键值对。
覆盖测试运行程序:
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