Carl Rynegardh
Carl Rynegardh

Reputation: 558

Receiving value from another column in SpecFlow Feature file with Examples

I'm writing BDD Tests with SpecFlow in c#. I'm trying to, in a beautiful way, take the value of one of the columns and use it as input to another column. Code:

Examples:
| volume    | error |
|  0        | Volume must be greater than 0 but is <volume> | 

I'd like <volume> to take the value 0 in this case. Is this possible? This is obviously not working at the moment. Thanks :)

Upvotes: 1

Views: 533

Answers (2)

Dr. Crunk
Dr. Crunk

Reputation: 1

Yes, it is possible as below:

Given the error message is <error> for <volume>:

Examples:
| volume    | error |
|  0        | Volume must be greater than 0 but is %1 |

In your StepDef file:

@Given("The error message is {string} for {string})
public void printError(String volume, String error) {
    error=error.replace("%1", error);
    System.out.println(error); // prints correctly with replacement
}

Upvotes: 0

Szabo Peter
Szabo Peter

Reputation: 514

No, it is not possible. One could argue that the connection between the two volume values would be more noticeable, easier to understand, but if you actually substitute 0 in this case, it will be perfectly understandable. If you do want to emphasize the connection, you could write another scenario outline along the lines:

Given the volume has been set to <volume>
When action is triggered
Then the error message should be "Volume must be greater than 0 but is <volume>"

And then all your examples with nonpositive numbers.

Upvotes: 3

Related Questions