Run Cucumber 5 tests with tags

Hi All,

I have a BDD cucumber project using TestNg and Junit tests. I want to run them with the cucumber tags from command line or from CI/Cd pipeline. Whenever I run with the command .\gradlew test -DincludleTags=“Regression”, it doesnt run the tests successfully. Can you anyone please let me know hoe to achieve this?

Is there any config need to be added on the gradle.build file.

I have no idea about cucumber or its tags.
But if it requries that you set the system property includeTags (or includleTags if it was not a typo), then you need to set this on the test task.
By giving it with -D on the command line, you just set it for the Gradle process, but test are run in a sepratate process.
Only the system properties you set / map yourself are forwarded.
You can also consider using a Gradle property instead of system property to select which tests to run, then you could also set it for example in <GRADLE_USER_HOME>/gradle.properties if you like.
Another alternative is, to have different test tasks for different hard-coded tags, then you can just choose which task you run.

Thanks. I used includeTags in the system properties as well, but it didn’t work.

What do you mean with “as well”?
What did you try?

I tried with includeTags option as well, I didnt work

You original description shows a try with setting a system property on the Gradle daemon.
I told you why that cannot work and how to fix it (if cucumber actually evaluates that system property).

Also, a quick look in the cucumber documentation would have shown you, that you can run cucumber through JUnit Platform and in that case have the cucumber tags as JUnit tags so could use includeTags and if you run through JUnit 4 or TestNG, that the system property you need is cucumber.filter.tags which can contain an expression with and, or, parentheses, …

I passed system property like this in test systemProperty “cucumber.filter.tags”, System.getProperty(“cucumber.filter.tags”)

and used this command to run tests with tags

./gradlew test --tests TestRunner -Dcucumber.filter.tags=“@regression” it just runs all test instead of tests that are tagged with @regression

Well, as I said, I’m not familiar with Cucumber and it is less a Gradle question than a Cucumber question.
You should maybe ask in a Cucumber forum, or at least provide an MCVE

Thanks for the information. I was having the same issue.

Thanks for the information, I was facing the same issue.