小黄瓜:允许后退一步吗?

Gherkin: Is it allowed to go back one step?

写小黄瓜时允许后退一步吗?

例如我可以写 Given - When - Then - When - Then?

如果不是 - 为什么?

不允许后退一步

Gherkin 不是图灵完备的编程语言。它不支持重复或条件。

您使用 Gherkin 来描述特定行为。只有一次通过的场景。因此,您不需要在一个场景中使用不同的执行路径。如果你need/want描述另一个行为(执行路径)你应该写另一个场景。

这可能感觉像是一种创建重复的方式,也许确实如此。但它也是一种创建易于理解和推理的示例的方法。最重要的是,为非程序员验证。

如果你的字面意思是在同一个场景中再次执行该步骤,则为否,但是,如果你的意思是返回使用 Given When Then And & But 等词,则可以接受table.

也就是说,您可以编写如下场景:

Feature: This is a test

Scenario: I must write an example
 Given I do this
 And this should be done also
 Then I should see this
 When I do this
 Then I should see this
 When I do this other thing
 Then I should now see this

如果你想倒退,两种方法,acceptable.

使用场景大纲

Feature: This is a test

Scenario Outline: I must write an example
 Given I do this
 And this should be done also
 Then I should see this
 When I do <this>
 Then I should see <that>

Examples:
| this  | that  |
| this1 | that1 |
| this2 | that2 |

注意 示例 table 使用 header 行,在上面的场景大纲中用在这两个括号之间:<>

使用背景

Feature: This is a test

Background:
 Given I do this
 And this should be done also
 Then I should see this

Scenario: I must write an example
 When I do this
 Then I should see that

Scenario: I must write another example
 When I do this thing differs from the last scenario
 Then I should see thing which differs from the last scenario