Reputation: 59
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
Reputation: 141
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
}
Upvotes: 2
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