2013-12-16 84 views
1

我有以下的小黃瓜:同一步驟定義

Given i go to the URL 
And i enter the <NRIC or FIN> as NRIC/FIN 
And i select the option to proceed Next 
And i select the first available available Handset Color 
And i select the option to proceed Next 
And i enter <Full Name> as Name 
When i select the option to proceed Next 

的「I select the option to proceed Next」出現了三次。這應該如何寫在Step Definitions Java類文件中?

回答

1

在編寫黃瓜場景時,您可以採用命令式或聲明式樣式。我寧願寫下同樣的東西。

Given i go to the URL 
And i enter NRIC/FIN 
And i select the first available Handset Color 
And i enter <Full Name> as Name 
Then I should see that 

因此,這取決於誰將讀取您的方案。一個值得閱讀的鏈接是imperative - declarative

3

除了聲明性/命令性問題,還有一個關於你描述什麼需求的思考。出於這個原因,我發現在示例中包含Scenario:會很有幫助。在給定步驟中獲得這些詳細信息非常不尋常

您是否正在測試訂單的創建(猜測位)?如果是的話那麼你的輸入/選擇步驟應該是Whens的情況下,所以是這樣的:

Scenario: Create a new order 
    Given I have gone to the URL 
    When I enter the NRIC/FIN: <NRIC/FIN> 
    And I choose the first available Handset Colour 
    And I enter <Full Name> as Name 
    Then my new order should be confirmed (or whatever) 

但是,如果你創建僅僅爲了設置場景來測試別的東西,那麼你可以欺騙和剛剛指出的順序應該存在:

Scenario: Check the status of an order 
    Given that I have created an order: 
     | NRIC/FIN | Colour | Full Name | 
     | xxxxx | Red | John Doe | 
    When I check the status of my order 
    Then I should see a new order... 

它是由自動化是否點擊在屏幕中創造秩序或只是將其插入到數據庫中,所有重要的是,到時候你到命令應該存在的時候。

在一個理想的BDD世界中,小黃瓜會在實現之前寫出來,但它往往不會這樣工作。我仍然覺得嘗試假裝我在那個理想世界中編寫功能是有用的。問:「在我們開始開發之前,我會怎樣寫這個?」可以幫助從實施細節中分離實際需求(我可以輸入訂單)(在輸入每項數據後,我點擊下一步)。