描述小黄瓜语言的“等待”步骤

时间:2015-03-31 08:21:46

标签: bdd gherkin

我正在尝试用小黄瓜语言描述我的应用程序的场景,以便我可以将其用作可执行规范。该场景更少以下内容:执行检查的过程有一个阶段。如果满足检查的所有条件,则过程结束。否则,进程会等待任何条件发生变化(已通知此情况)并再次进行检查,如果成功则结束。我所遇到的问题就是这个等待的部分。我当前的版本(简化)是:

Given condition A 
And not condition B
When the check is performed
Then the result is negative, pending condition B

我试图用pending condition B表达的是,一旦条件B改变,测试将重复,但我不特别喜欢这个版本,因为很难将一对一转向测试(事件condition B更改为新When)。

任何有更多经验的人都可以提出更好的配方吗?

1 个答案:

答案 0 :(得分:0)

您可以将两个测试链接在一起,如下所示:

Scenario: When A and not B result is negative, but if B happens then result is positive
  Given condition A 
  But not condition B
  Then the check returns negative
  But if condition B
  Then the check returns positive

这可能不是最佳做法,但有时候是务实的做事方式,特别是如果由于受测试的系统或您的测试环境而导致测试运行缓慢。

或者你可以把它分成两个场景,在幕后重复一遍。

Scenario: When A and not B the result is negative
  Given condition A 
  But not condition B
  Then the check returns negative

Scenario: When A and B the result should be positive
  Given the system has condition A but not B
  And the check is returning negative
  When condition B
  Then the check returns positive

在你的情况下,我会说选择哪一个取决于你的测试运行多长时间。如果它们很慢,那就选择一个大的场景。如果他们不是,或者由于某种原因并不重要,那就去寻求第二个建议。第二个建议将提供有关失败原因的更多信息,但是如果测试速度很慢,那么即使你使用一个大的场景,我认为测试失败的原因仍然很明显。 / p>

相关问题