10

I have this feature file:

Scenario Outline: Example
    Given I am a user
    When I enter <x> as an amount
    Then the result should be <result>
    Examples:
        | x | result |
        | 3 | 3      |
        | 1 | 1      |

My issue is that after it's run, each example is labeled as variant #

Is there a way to name what each example line is actually testing, so that in the report, we know better what is tested, not just:

Scenario: Example, Variant 0
Scenario: Example, Variant 1
Scenario: Example, Variant 2

I'm trying to help our testers get more meaningful reports; there is typically a reason they write multiple examples, and they want that reason for that example shown somehow.

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
CaffGeek
  • 21,856
  • 17
  • 100
  • 184

1 Answers1

13

As the SpecFlow Scenario Outlines documentation says:

the Gherkin syntax does not enforce that all example columns have the matching placeholder in the scenario outline, you can even introduce an arbitrary column in the example sets for better test method name readability

So you could introduce an arbitrary column into your "Examples" table to succinctly describe the intention of the test e.g.

Scenario Outline: Example
    Given I am a user
    When I enter <x> as an amount
    Then the result should be <result>
    Examples:
        | example description   | x | result |
        | Example Description 1 | 3 | 3      |
        | Example Description 2 | 1 | 1      |

This would result in the following test names:

Example_ExampleDescription1
Example_ExampleDescription2
Ben Smith
  • 19,589
  • 6
  • 65
  • 93
  • 1
    @CaffGeek Cool. Let me know how you get on. – Ben Smith Feb 21 '14 at 23:19
  • 5
    If anyone has having trouble with SpecFlow still using the "variant" naming schema even after adding a label column make sure that all the values therein are unique! A single dupe will cause it to revert back. – David Peters Jun 28 '17 at 19:36
  • @DavidPeters thank you so much for this. Was doing my head in. – Chris Jan 12 '18 at 11:35
  • 2
    I dont understand how this works. My test name always describe the full example table row e.g. test name is: NP10_New_Record_Details_Tab_Info("Prod010a","Product","01/10/2020","10.00",null) How do you get it to only use one Example table column in the test name? – m_finn Oct 13 '20 at 10:47
  • @m_finn do you have solution to have short name? – cashmere Jul 07 '22 at 13:16
  • @cashmere - I asked the question here but dont think i got a solution (reply from Specflow) https://stackoverflow.com/questions/64331788/specflow-scenario-outline-change-auto-generated-test-name Sorry i cant check as no longer work there. – m_finn Jul 11 '22 at 08:37