0

假设我有一个Main.story文件,其中包含 -

  1. 登录场景
  2. 搜索场景
  3. 添加到购物车场景
  4. 更新数量方案
  5. 结帐场景

但现在如果我只想跑——

Login Scenario → Search Scenario → AddToCart Scenario → Checkout Scenario并跳过UpdateQuantity 场景

如果不从故事文件中删除/删除任何内容,我怎么可能实现这一点。

4

1 回答 1

0

BDD 风格的场景是完全独立的。在这种情况下,您将有两种情况:

Scenario: I can check out with an updated order quantity
Given I login
And I search
And I add to the cart
And I update the quantity
When I checkout
Then I get a confirmation email (or whatever)

Scenario: I can purchase items
Given I login
And I search
And I add to the cart
And I update the quantity
When I checkout
Then I get a confirmation email (or whatever)

如果担心这些步骤中的每一个实际上都是几个步骤,并且在有 20 个给定的场景中看起来真的很难看,那么只要单独测试这些动作中的每一个,您就可以使用复合步骤。这是一个在其定义中调用其他步骤的步骤(通过代码,而不是 Gherkin)。你采取同样的行动,但小黄瓜的条目要少得多。

重要的部分是,任何场景都不应需要 BDD 中先前场景的操作。

为了进一步澄清,如果你真的需要,有一种方法可以重新排序,但这是非常糟糕的做法。如果您选择走那条路,请参阅以下问题:

我如何在 Serenity BDD Jbehave 中按特定顺序执行故事文件

于 2018-01-16T17:21:32.620 回答