小黄瓜:是否可以退后一步?

时间:2016-02-09 08:23:04

标签: gherkin

写小黄瓜的时候可以退一步吗?

例如,我可以写给定 - 当 - 然后 - 何时 - 然后?

如果不是 - 为什么?

2 个答案:

答案 0 :(得分:1)

不允许退回一步。

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

您使用Gherkin描述特定行为。只有一次传递的场景。因此,在一个方案中不需要不同的执行路径。如果您需要/想要描述另一个行为(执行路径),您应该编写另一个场景。

这可能是一种创建重复的方式,也许就是这样。但它也是一种创建易于理解和推理的示例的方法。最重要的是,验证非程序员。

答案 1 :(得分:0)

如果你的意思是回到在同一场景中再次执行该步骤,那么这是一个否定的,但是,如果你的意思是回到使用给予当时的话和&但是,那是可以接受的。

意思是,你可以编写一个类似的场景:

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

如果你想倒退,那么 有两种方法可以接受。

使用方案大纲

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 |

注意示例表使用标题行,在此处两个括号之间的场景大纲中使用:<>

使用背景

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
相关问题