我提出了一个类似的问题,但措辞很糟糕,所以并没有真正得到我想要的答案。这是另一个尝试:
所以我很欣赏 Cucumber 的 Gherkin Given 语句类似于测试用例的前置条件。我很欣赏一些人认为这些不应该涉及用户交互,但为了这个问题,我将不同意这种观点。
以下是三种情况:
Scenario: Test a song can be played
Given I setup a new account and default user
When I add a "2nd" user
And the "2nd" user starts playing a song
Then I should see a song is playing
Scenario: Test a playing song being stopped (version A)
Given I setup a new account and default user
And I add a "2nd" user
And the "2nd" user starts playing a song
When the "2nd" user stops playing a song
Then I should see a song is not playing
Scenario: Test a playing song being stopped (version B)
Given a "2nd" user is playing a song
When the "2nd" user stops playing a song
Then I should see a song is not playing
所以我很欣赏上面的版本 B 从业务用户的角度来看比版本 A 更好。但是,从代码重用的角度来看,版本 B 肯定需要 Given 语句来重复在第一个场景的大多数情况下使用的代码?
干杯,
查理