Running a Subset of Scenarios

As the number of features and scenarios grows, we’ll frequently run into situations where we want to run only a single (or maybe a couple) of scenarios to get faster feedback. This can be if we are working on a new scenario or if we have broken an existing one. Let’s take a closer look at how this works.

Filtering with Tag Expressions

The simplest way to use the --tags option is to give it a single tag to run, for example:

 $ ​​cucumber​​ ​​--tags​​ ​​@focus

This would cause Cucumber to run just the scenarios tagged with @focus. It’s quite common to temporarily tag a scenario or feature with a unique tag like this to filter what to run.

In some situations, we may want a little more control over the tag filtering. Imagine that we have made some changes to a piece of our application that sends out emails. What if we want to run all scenarios tagged with @focus or @email? Here is how:

 $ ​​cucumber​​ ​​--tags​​ ​​@focus,@email

If the feature file has more than one scenario, it will run only the one on line 45. The line number can be anywhere in the feature, ranging from a comment line to the last step (including a step table or doc string).

You have probably noticed that Cucumber prints out the location of a feature file with the line number in error messages.

 features/something.feature:45

If you want to rerun the scenario that failed, just select the text and paste it:

 $ ​​cucumber​​ ​​features/something.feature:45

This is equivalent to using the --line option. The colon notation also allows you to specify several line numbers, allowing you to specify several scenarios to run:

 $ ​​cucumber​​ ​​features/something.feature:45:89:107

If you prefer, you can also do this using the --lines argument. Cucumber doesn’t mind whether you say --line or --lines.

Filtering on Names

If tag and line filtering still doesn’t meet your needs, you can filter scenarios based on name. Say, for example, that you want to run all scenarios that have the text logout in their name and that they are scattered around several feature files without a particular tag to identify them. Running them is just a matter of the following:

 $ ​​cucumber​​ ​​--name​​ ​​logout

In a similar fashion, you can also --exclude scenarios with a certain name.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43