SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Be able to access the Example set name at Runtime

Open SabotageAndi opened this issue 3 years ago • 3 comments

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.

SabotageAndi avatar Jul 09 '21 14:07 SabotageAndi

@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?

HermanCodes avatar Jul 12 '21 22:07 HermanCodes

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

JordanWestern avatar Jul 13 '21 09:07 JordanWestern

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,

SabotageAndi avatar Jul 15 '21 08:07 SabotageAndi