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

后端 未结 2 852
春和景丽
春和景丽 2021-01-25 06:20

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

相关标签:
2条回答
  • 2021-01-25 06:54

    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.

    0 讨论(0)
  • 2021-01-25 06:55

    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

    0 讨论(0)
提交回复
热议问题