【发布时间】:2015-05-06 11:11:38
【问题描述】:
在我们使用 cucumber-jvm 进行 web 测试的项目中,我遇到了一个到目前为止我无法解决的问题:Se 有几个 Scenario Outlines 应该都使用相同的Examples。现在,我当然可以将这些示例复制到每个示例中,但是如果您可以执行以下操作,它会更短(并且可能更容易理解):
Background:
Examples:
| name |
| Alice |
| Bob |
Scenario Outline: Flying to the conference
Given I'm flying to a confernce
When I try to check in at the airport
And my name is <name>
Then I should get my plane ticket
Scenario Outline: Collecting the conference ticket
Given I'm at a conference
When I ask for the ticket for <name>
And show my business card to prove my id
Then I should get my conference ticket
Scenario Outline: Collectiong my personalized swag bag
Given I'm at a conference
When I go to the first booth
And show them my conference ticket with the name <name>
Then they'll give me a swag bag with the name <name> printed onto it
这样的事情可能吗?如果是这样,怎么做?我会按照here 的建议使用某种工厂吗?如果有,有什么推荐的吗?
【问题讨论】:
-
您是否需要将整个功能运行两次,一次使用 alice,一次使用 bob,或者您可以在所需步骤中使用名称列表吗?
-
@Dude 这个想法是用每个名字运行整个功能。
-
对所有用户运行所有场景的额外好处是什么?为什么不混合和匹配(一个用户运行一些,另一个用户运行一些)。如果用户 Bob 和 Alice 都应该通过所有场景,那么您通过为两个用户运行一个场景来真正测试什么?
-
当然要看情况;虽然我不记得我问这个问题时的具体情况,但可能的原因是某些场景对于分配给他们的某些数据库中具有不同值的不同用户应该发挥相同的作用。在上面的例子中,也许我想确保女性和男性得到平等对待。或者那个年龄不会改变结果。
标签: cucumber cucumber-jvm gherkin