问题
I am trying to run Cucumber tests on Google Firebase Test Lab but I am having trouble figuring out how to pass a Gradle project setting to the gcloud firebase test android run
command.
As background, the tutorial Android BDD with Cucumber and Espresso — the full guide does a great job explaining how to setup Cucumber for an Android project and run it locally like this:
./gradlew connectedAndroidTest -Pcucumber
The -Pcucumber
flag switches between AndroidJUnitRunner
and CucumberTestRunner
in the module-level build.gradle file:
def getInstrumentation() {
project.hasProperty('cucumber') ?
'com.teadate.bdd.cucumber.runner.CucumberTestRunner' :
'androidx.test.runner.AndroidJUnitRunner'
}
android {
// ...
defaultConfig {
// ...
testInstrumentationRunner getInstrumentation()
}
}
One possible way to pass the cucumber
flag is by adding it to my gradle.properties file (which I figured out from this post):
Add to gradle.properties:
cucumber
I'm pretty sure this will work because it does cause ./gradlew connectedAndroidTest
to use CucumberTestRunner
instead of AndroidJUnitRunner
. But is there a way to pass -Pcucumber
to gcloud firebase test android run
?
I've read that gcloud firebase test android run
allows you to pass environment variables with the parameter [--environment-variables](https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run#--environment-variables)
, however, I don't think it will use those as gradle project settings because it passes them either to the am instrument
command and/or the test runner:
The environment variables are mirrored as extra options to the am instrument -e KEY1 VALUE1 … command and passed to your test runner (typically AndroidJUnitRunner).
In my case, I'm trying to use the -Pcucumber
flag to configure which test runner to call. Thus I need the flag used before the test runner is even known.
A workaround to this problem might be to tell gcloud firebase test android run
to use a specific test runner by passing --test-runner-class. But that solution, if it works, only works around this particular case. What if I had a gradle project setting that's not available as a parameter to gcloud firebase test android run
?
Lastly, someone asked a similar question about Passing a parameter to gcloud app via Jenkins but that didn't concern a gradle project setting, it was just about syntax for passing a value to a gcloud firebase test android run
parameter, namely --device
Can I pass a gradle project setting on the command line to gcloud firebase test android run
?
来源:https://stackoverflow.com/questions/57538106/how-to-pass-gradle-project-settings-on-the-command-line-to-gcloud-firebase-test