How to run tests filtered using cucumber-jvm and gradle tags?

I have been working with cucumber for some time, and now I want to transfer the use of the test set to gradle from maven.

I was able to prepare a project covering the main use, running tests, getting results, etc. The last part that I skip is the ability to run tests only for specific tags. Acceptance testing is carried out using the product:

productFlavors {
    uats {
        testInstrumentationRunner "com.paddy.cuespton.cuespton.test.Instrumentation"
    }

    full {
        applicationId "com.paddy.app.cuespton"
        versionName "1.0"
    }
}

Allows you to run tests with the task:

./gradlew connectedAndroidTestUatsDebug

Is it possible to add a param parameter with a tag to this task to run only certain tests?

https://github.com/samueltbrown/gradle-cucumber-plugin/ , , Android - .

, , https://github.com/paddyzab/espresso-cucumber-sandbox.

!

+4
1

, , , (sample repo):

1) buildConfigField uats:

Uats {
        testInstrumentationRunner "com.quandoo.gradletestpoc.test.Instrumentation"

        // passing instrumentation parameters
        buildConfigField "String", "TAGS", "\"${getTagsProperty()}\""
    }

2) getTagsProperty():

 def getTagsProperty() {
     return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
 }

3) onCreate() :

private static final String TAGS_KEY = "tags";
......
@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);

    // Reading runner params
    String tags = BuildConfig.TAGS;
    if (!tags.isEmpty()) {
        bundle.putString(TAGS_KEY, tags);
    }

    instrumentationCore.create(bundle);
    start();
}

4)

./gradlew connectedAndroidTestUatsDebug -Ptags="@bar"

!

+5

Source: https://habr.com/ru/post/1569803/


All Articles