2015-03-31 79 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 

在你的情況下,我會說,哪一個取捨就看你的測試需要多長時間才能運行。如果他們很慢,那麼去一個大場景。如果他們不是,或者由於某種原因沒有關係,那就去做第二個建議。第二個建議將提供更多關於失敗原因的信息,但如果測試速度很慢,那麼我認爲即使您使用的是一個大場景,測試失敗的原因仍然很明顯。