简体   繁体   中英

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

It's usually better to keep your Given s and When s 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
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM