我有以下情况:
Scenario: Create a game with valid information
Given I am logged in
When I visit the new game page
And I fill in "Game type" with "Basketball"
And I fill in "Zip code" with "94040"
And I fill in "Description" with "Friendly match"
And I click on the button "Create Game"
Then I should see "Awesome! Your game has been created."
Scenario: Create a game with missing information
Given I am logged in
When I visit the new game page
And I fill in "Zip code" with "94040"
And I fill in "Description" with "Friendly match"
And I click on the button "Create Game"
Then I should see "Game type can't be blank."
正如您所看到的,我正在重复代码并且作为开发人员的观点,我讨厌在两种情况下都重复一些句子。但是,我认为场景必须是独立的,所以任何利益相关者都可以看看并说......哦,我知道这个场景描述的是什么。
我正在尝试测试我的表单验证是否适用于不同类型的字段值。所以,我会有很多类似的场景,基本上会改变" 填写"部分。因此,另一个类似/相关的场景是检查邮政编码必须是数字的场景:
Scenario: Create a game with invalid zip code
Given I am logged in
When I visit the new game page
And I fill in "Game type" with "Basketball"
And I fill in "Zip code" with "ffff"
And I fill in "Description" with "Friendly match"
And I click on the button "Create Game"
Then I should see "Zip code has to contain 5 digits."
所以,我的问题是:有没有 DRY ,商务人士友好的做法?我的意思是,在代码优化和清晰易懂的独立场景定义之间取得平衡?