Scenario outlines are very handy for creating data driven tests, but the number of scenarios increases with the number of examples. I\'ve gotten in the habit of tagging scenario
This is the way I do it:
@job-openings
Scenario Outline: Adding a job opening with experience
Given a job exists
When I add a job opening requiring years and months experience
Then a job opening should exist requiring years and months experience
@smoketest @regression
Examples:
| years | months |
| 2 | 6 | # <-- the "prototypical" example I want to tag
@regression
Examples:
| years | months |
| 0 | 1 |
| 0 | 11 |
| 1 | 0 |
| 99 | 0 |
| 99 | 11 |
| 100 | 0 |
There are two example sections that both belong to the scenario. The smoketest has its own example section. When running
dotnet test --filter "TestCategory=job-opening&TestCategory=smoketest"
it will only run the example with the smoketest tag. When running
dotnet test --filter "TestCategory=job-opening&TestCategory=regression"
it will run all the examples. It will also run the smoketest because it has the regression tag too.
user1207289's method also works. I sometimes do it that way when a test breaks and I want to retest it later. When the tests are generated the specific example you want to run will get a name (e.g. AddingAJob_ExampleYears2Months6). You can find the name of the generated unit tests in the scenario with the -t
flag, which lists all the tests:
dotnet test --filter "TestCategory=job-opening" -t
To run one specific test (technically all tests with AddingAJob_ExampleYears2Months6 in the name):
dotnet test --filter AddingAJob_ExampleYears2Months6
I used the official dotnet cli tool in the examples above, but it's pretty similar for the other test runners.