Home > Blockchain >  If there are 1000 features files in Cucumber feature file and I want to execute only even feature fi
If there are 1000 features files in Cucumber feature file and I want to execute only even feature fi

Time:12-06

1000 feature files in src/test/resources. I want to run only the features file which are even( 2, 4, 6,......1000) how can we do that?

I tried to group them but not sure like this will be good approach.

CodePudding user response:

In Cucumber, you can use tags to specify which feature files or scenarios should be executed. To run only the even feature files in your project, you can add a tag to each of those files and then use that tag to filter which files should be executed.

For example, let's say you have added a tag called @even to each of the even feature files. You can then use the @even tag in your Cucumber command to run only those files, like this:

cucumber -t @even

This will run all of the feature files that have the @even tag, and skip any files that do not have that tag.

Alternatively, you can use the --tags option in your Cucumber command to specify a regular expression that matches the tag names of the feature files you want to run. For example, to run all feature files with a tag that ends in an even number, you could use a regular expression like this:

cucumber -t /@\d*[02468]$/

This regular expression will match any tag that ends in a digit that is an even number (0, 2, 4, 6, or 8).

Overall, using tags and regular expressions in your Cucumber commands can be a powerful way to control which feature files and scenarios are executed and can help you run only the tests that are relevant to your current needs.

CodePudding user response:

If you are using JUnit 5 with Cucumber the you can use a PostDiscoveryFilter from the JUnit Platform to filter out tests.

Something like:

public FilterResult apply(TestDescriptor t) {
   
   // Determine if test descriptor is a feature file based on t.getSource()

   Collection siblings = t.getParent().getChildren();

   // Find index of t in siblings
   // decide to keep or not if index is even


}
  • Related