问题
I have the following scenario definition in a sample.feature
file, with scenario with two sub-cases using the Examples
syntax:
@ninja
Scenario Outline: this is a sample scenario
Given ...
And ...
And ..
When ...
Then ...
Examples:
| param1 | param2 | param3 |
| 10 | 4 | 9 |
| 20 | 8 | 23 |
I can use the tag ninja
to execute only that scenario, among all the others defined in the sample.feature
file, as follows:
$ behave sample.feature --tags=ninja
...
Scenario Outline: this is a sample scenario -- @1.1
...
Scenario Outline: this is a sample scenario -- @1.2
...
Note that behave "marks" each subcase execution, i.e. @1.1
and @1.2
in execution log.
I'd like to know if I can be even more "sharp" and use behave to execute only one (or a subset) of subcases of a given tag. I have tried the following, with no luck (i.e. both subcases are executes, not only the second one):
$ behave sample.feature --tags=ninja,1.2
Is that possible? Any help on how doing it, please?
回答1:
Yes, it is possible to execute only one row in a Scenario Outline (Examples), first is necessary to define a placeholder in the tag into the feature file, example:@test.row<row.id>
Reference in Behave
After, to execute:
behave example.feature -t
@test.row1.2
-- run only the row: 2 with this tag.
Also it is posible create several examples, like this:
Examples:
| param1 | param2 | param3 |
| 10 | 4 | 9 |
| 20 | 8 | 23 |
Examples:
| param1 | param2 | param3 |
| 30 | 12 | 1 |
| 40 | 13 | 45 |
| 50 | 14 | 49 |
| 60 | 15 | 13 |
And,
behave example.feature -t
@test.row2.4
-- run only the row: 4 in the second examples with this tag:
| 60 | 15 | 13 |
来源:https://stackoverflow.com/questions/45186323/use-behave-tags-to-execute-only-a-subcase-of-such-tag