2015-03-31 83 views
1

我想描述一下我的应用程序在小黄瓜语言中的一个场景,以便我可以将它用作可执行规范。这种情况更多地少于以下情况:执行检查的过程有一个阶段。如果检查的所有条件都满足,则过程结束。否则,流程会等待任何条件发生变化(通知它)并再次检查,如果成功则结束。我无法描述的是这个等待的部分。我现在的版本(简体)是:描述在小黄瓜语言上的“等待”步骤

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)。

任何有更多经验的人都可以提出一个更好的表述吗?

回答

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 

在你的情况下,我会说,哪一个取舍就看你的测试需要多长时间才能运行。如果他们很慢,那么去一个大场景。如果他们不是,或者由于某种原因没有关系,那就去做第二个建议。第二个建议将提供更多关于失败原因的信息,但如果测试速度很慢,那么我认为即使您使用的是一个大场景,测试失败的原因仍然很明显。