Can you tag individual examples in a scenario outline in SpecFlow?

匆匆过客 提交于 2020-12-26 13:50:49

问题


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 scenarios to make it easier to filter on major features of our application.

I would like to set up a "smoke test" that hits all the major use cases. Some of these use cases are captured in scenario outlines that perform boundary testing on dates or numbers, but I just want to hit that one prototypical case within the examples.

For instance say we've got a feature allowing us to add job openings to a job (basically a "hiring opportunity" versus "we have warm bodies filling this position").

On screen we have two form fields for the minimum experience: years and months. The user should not enter more than 11 months in the months field, otherwise they should put something in the years field (e.g. 18 months should actually be 1 year and 6 months).

@job-openings
Scenario Outline: Adding a job opening with experience
    Given a job exists
    When I add a job opening requiring <years> years and <months> months experience
    Then a job opening should exist requiring <years> years and <months> months experience

Examples:
    | years | months |
    | 0     | 1      |
    | 0     | 11     |
    | 1     | 0      |
    | 2     | 6      | # <-- the "prototypical" example I want to tag
    | 99    | 0      |
    | 99    | 11     |
    | 100   | 0      |

Having those examples hitting the boundaries of the acceptable values for years and months is definitely useful from a regression testing standpoint, but not when performing a "smoke test" of the system. It would be nice to run a single example in the scenario outline that represents a typical use case. As some background info, we have a PowerShell script that developers use to run automated tests of all sorts, and a general "smoke test" hitting all the major features would be useful.

Is there a way to tag an individual example in a scenario outline?


回答1:


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> years and <months> months experience
    Then a job opening should exist requiring <years> years and <months> 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.




回答2:


I am able to run single example from scenario outline by below command

C:\Users\..\..\bin\Debug>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" yourTests.exe /Tests:yourTestName

where yourTestName is the name of the test that is generated in test explorer upon build and yourTests.exe is the generated exe in /bin/debug. I am using MSTest

For more info on names generated look here



来源:https://stackoverflow.com/questions/57992278/can-you-tag-individual-examples-in-a-scenario-outline-in-specflow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!