SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.25k stars 754 forks source link

Be able to access the Example set name at Runtime #2461

Open SabotageAndi opened 3 years ago

SabotageAndi commented 3 years ago

Link to Feature Request

No response

Implementation Idea

It is possible to have multiple Example tables/set and name then.

Like this:

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples: Small
    | start | eat | left |
    |    12 |   5 |    7 |
    |    20 |   5 |   15 |

  Examples: Big
    | start | eat | left |
    |  1200 |   5 | 1195 |
    |  2000 |   5 | 1995 |

At the moment it is not possible to access the name of the Example Set/Table at Runtime.

What needs to be changed that we can get this at Runtime?

  1. Enhance ScenarioInfo with a property for it and This should be a readonly string property named ExampleTableName, which get set via the constructor

Values of the property: Scenario: String.Empty Scenario Outline - no name specified at the example table: ExampleSet 0 - the same as currently - https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs#L329 Scenario Outline - name specified: the specified name

  1. Adjust code-behind file generation, that the information can set

General: Add an additional parameter to the generated testmethods to accept the example table name - https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs#L486

xUnit: The name of the example table has to be added to the generation of the InlineDataAttribute - https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs#L88

NUnit: The name of the example table has to be added to the generation of the TestCaseAttribute - https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs#L141

MSTest: This is a little bit trickier because we don't support the DataRow attribute yet. Probably the changes have to made at https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestGeneratorProvider.cs#L200 or https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestV2GeneratorProvider.cs#L78

SpecFlow+ Runner: We will take care of it

Please also add unit tests and some scenarios to our tests for this.

HermanCodes commented 3 years ago

@SabotageAndi So I am starting to just have a play around in a new branch, what is the best way for me to test my changes to ensure that they work?

JordanWestern commented 3 years ago

@HermanCodes add a reference to the local project inside of your plugin. Lets spend some time on discord this week working through it

SabotageAndi commented 3 years ago

For xUnit, you will see the changes immediately because we are using it to build the specs of SpecFlow with it. So I would start writing a scenario for this feature and then start getting it to get working. First that SpecFlow itself compiles again and then run the scenarios for the different unit test provider until they are green,