J OpenDock
J OpenDock

Reputation: 59

Specflow feature file code- data definition c#

I've created a feature file with multiple features. In my feature files my Given and When is always the same only my then is different as i'm testing for different output measures. Would it be worth having just one piece code for my Given and When and one code for my Then to validate all the output measures in one go.

If this is something that is possible how would i go about doing it?

Example:

Given Interface is generated
When batch is executed
Then transfer measure is generated

Given Interface is generated
When batch is executed
Then allocation measure is generated

Upvotes: 0

Views: 528

Answers (2)

Ivan Petkov
Ivan Petkov

Reputation: 141

It's usually better to keep your Givens and Whens separate, so that your features read better.

In your case, the best thing to do is use a Scenario Outline rather than a Scenario. This allows you to use a tokenised table to assert multiple different outcomes, given the same initial steps:

Scenario Outline: Batch execution works correctly
    Given  Interface is generated
    When batch is executed
    Then <measure_type> is generated
Examples: 
    | measure_type       |
    | transfer measure   |
    | allocation measure |

In your steps, you'd have separate methods asserting that the correct measure type has been generated:

[Then(@"transfer measure is generated")]
public void ThenTransferMeasureIsGenerated()
{
    // your assertion logic here
}

Upvotes: 2

Hagashen Naidu
Hagashen Naidu

Reputation: 128

For your Examples

Given Interface is generated

When batch is executed

Then transfer measure is generated

Given Interface is generated

When batch is executed

Then allocation measure is generated

You could either use a table and change it as follows:

Given Interface is generated    
When batch is executed   
Then '<val>' measure is generated    
Examples:    
|val|    
|transfer|    
|allocation|

This will generate a single Then step

Upvotes: 0

Related Questions