问题
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