Scenario outlines
The first 2 scenarios in our feature file look almost identical. The only difference is that Sean is in a slightly different location, which affects whether Lucy can hear his shout or not.
We can combine these 2 scenarios using a single scenario outline.
HearShout.feature
# ...
Scenario Outline: only hear in-range shouts
Given Lucy is at 0, 0
And Sean is at <Seans-location>
When Sean shouts
Then Lucy should hear <what-Lucy-hears>
Examples: some simple examples
| Seans-location | what-Lucy-hears |
| 0, 900 | Sean |
| 800, 800 | nothing |
The lines that follow the Examples keyword are a Gherkin table. Each column is separated by a pipe character | and each new line is a separate row. The first row of the table contains column headings, which match text in the scenario outline.
Now replace the first 2 scenarios in HearShout.feature with the single scenario outline above and run SpecFlow again. You may find that you only need to edit the feature file - your existing step definitions probably won’t need changes.
discuss
- How many scenarios does SpecFlow now report as passing?
- A scenario outline can be followed by multiple
Examplestables each with their own name. Why might you want to do this?