我知道这些都可以,但我想成为红宝石/黄瓜社区的更好成员。我有一个故事,测试我的网站的多个部分没有任何链接,它不应该显示。那么这两种方式中的哪一种是编写场景的最佳方式。再次,我明白要么会工作,但我正在寻找最佳实践解决方案。我通常会使用选项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