2011-05-16 144 views
5

我正在創建一個多步註冊過程的黃瓜測試,並且對於方案步驟的最佳實踐有點不確定...黃瓜長度?

註冊中有4個表單/頁面。我應該循環通過給定,當在一個場景中4次或有更好的方式來組織它嗎?

到目前爲止,我有...

Scenario: Company User 
Given I am on the registration page 
When I follow "Register as a supplier" 
When I fill in the following: 
    | user_email | [email protected] | 
    | user_password | secret | 
    | user_password_confirmation | secret | 
And I press "Create login - Proceed to step 2" 
Then I should see "Create Company Profile" 
When I fill in the following: 
    | company_name | Test Company | 
    | company_description | Lorem | 
    | company_telephone | 01928740436 | 
    | company_email | [email protected] | 
And I press "Create company - Proceed to step 3" 
Then I should see "Test Company office(s)" 
+8

我會很失望,如果這實際上不是狡猾的影射。 – 2011-05-16 15:43:13

+0

這篇文章的標題讓我發笑:) – d11wtq 2011-05-16 17:01:53

+2

這對我來說看起來不錯,但如果它是我的代碼,我可能會將所有表單位提取到一個步驟定義中,並且會更一般:「當我設置了我的電子郵件和密碼「和」當我填寫我的公司信息「 – Unixmonkey 2011-05-16 18:52:59

回答

2

我會建議有4個場景覆蓋每一步的細節,如:

Given I am on step 2 
When I fill in the following: 
    | company_name | Test Company | 
    | company_description | Lorem | 
    | company_telephone | 01928740436 | 
    | company_email | [email protected] | 
And I press "Create company - Proceed to step 3" 
Then I should see "Test Company office(s)" 

您可以藏起來任何必要的,但不相關在「給定我在步驟X」的定義中填寫表格。

你或許應該也有一種情況,其涵蓋了如何組合在一起,例如:我認爲安迪韋特給了很好的意見

When I complete step 1 with valid information 
And I complete step 2 with valid information 
And I complete step 3 with valid information 
And I complete step 4 with valid information 
Then I should see "Thank you for registering" 
+0

謝謝你們對此的幫助。我已經淡化了這個功能,並在幕後給了它一些大的「萌芽」步驟。 – 2011-05-18 09:17:35

5

,而不是像第1步,第二步,等我的通用名稱將更多的描述:

When I register as a supplier with valid information 
And I create company profile with valid information 
And I ... with valid information 
And I ... with valid information 
Then I should see "Thank you for registering" 
+0

是的,這是一個很好的觀點。 – 2011-05-17 15:02:06

1

我喜歡馬克Irvine`s建議 - 黃瓜自動化的主要理念之一就是編寫的清晰讀者儘可能步驟。應該完全清楚,即使對於非程序員的人來說,測試正在做什麼。

如果您有興趣 - 您還可以閱讀Matt Wynne撰寫的「The Cucumber Book - 行爲驅動開發測試人員和開發人員」以獲取更多良好實踐。

問候, 亞歷