After pairing at Agile2009 with Paul, we introduced a new optional table section in the scenario which includes all the replaceable values of a scenario template. E.g.:
Given some stocks of <prices> and a <threshold>
When one of these stocks is traded at <price>
Then the trader is alerted with <status>
Examples:
prices |
threshold |
price |
status |
0.5,1.0 |
15.0 |
5.0 |
OFF |
0.5,1.0 |
15.0 |
11.0 |
OFF |
0.5,1.0 |
15.0 |
16.0 |
ON |
The presence of the Examples: keyword (which must be found after the steps at the end of the parseable portion of each scenario) triggers the execution of the scenario for as many times as the number of table data lines (i.e. excluding the first header line).
Note that the presence of <> is purely conventional, as it signals to the scenario writer that the parameter value will be picked up from the table. The parameters are injected via @Named annotations, e.g.:
@Given("some stocks of <prices> and a <threshold>")
public void pricesWithThreshold(@Named("prices") List<Double> prices, @Named("threshold") double threshold)
{
// ...
}
and it's the value of the @Named annotation that is used to read the value from the table.
Next step, is to have a similar mechanism at play using paranamer instead of annotations, so to offer developers the choice between the annotation-based and convention-based approaches.
Perhaps we could have table parser, referenced to by annotation, whereby each row of table represents a re-run of the same scenario with different parameters.