我知道這些都可以,但我想成爲紅寶石/黃瓜社區的更好成員。我有一個故事,測試我的網站的多個部分沒有任何鏈接,它不應該顯示。那麼這兩種方式中的哪一種是編寫場景的最佳方式。再次,我明白要麼會工作,但我正在尋找最佳實踐解決方案。我通常會使用選項B,因爲它們都測試不同的「然後」步驟;然而,我一直在進行一些研究,我第二次猜測我自己,因爲我可以用相同的給定語句測試所有場景,而且我正在閱讀,如果您要更改「給定」和「隨後」步驟。試圖完善我的黃瓜場景
A.
Scenario: A user that cannot access A, B, C, or D
Given I am a, user without access to A, B, C, or D
When I navigate to reports
Then I see the A header
But I cannot click on A's header
And I see error message under A stating the user does not have access
And I do not see the B section
And I do not see the C section
And I do not see the D section
OR
B.
Scenario: A user that cannot access A
Given I am a, user without access to A
When I navigate to reports
Then I see the A header
And I see error message under A stating the user does not have access
But I cannot click on A's header
Scenario: A user that cannot access B
Given I am a, user without access to B
When I navigate to reports
Then I do not see the B section
Scenario: A user that cannot access C
Given I am a, user without access to C
When I navigate to reports
Then I do not see the C section
Scenario: A user that cannot access D
Given I am a, user without access to D
When I navigate to reports
Then I do not see the D section
我不喜歡使用背景,因爲接下來的具體內容是什麼場景正在做的事情並不是全部記錄在場景塊內。儘管它減少了該功能中的代碼量,並且最終會重複自己,但是當場景失敗時,您將擁有場景中的所有信息來重新創建失敗。否則,你將不得不去挖掘背景信息或更糟,在掛鉤之前。 – 2013-03-07 20:01:28
如果開始重複自己,我只使用背景和乾燥作爲可能的下一步。乾燥的目的不是要減少代碼,而是要統一代碼並使其目的更加清晰。每個測試都應該清楚它的意圖。重複但不突出顯示的內容不應該分散注意力,也不應將注意力集中在我們測試中心的特徵/代碼上。 – AdamT 2013-03-07 20:16:46