1

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?

Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113
  • Have you found a solution to the above problem in the end? – Andrei Catinean Feb 04 '20 at 17:00
  • 1
    Sadly, no @AndreiCatinean. Instead of trying to use Cucumber, I merely adopted the Given/When/Then pattern for my Espresso tests using AndroidJUnitRunner. I abandoned cucumber because I anticipated I would run into too many problems like this one here because the community of people who use it is too small. I decided to stick with as much ordinary test framework technologies as possible because I generally find test frameworks are brittle. I wish languages writers would design their test framework before their language. – Michael Osofsky Feb 05 '20 at 00:27

0 Answers0