2

我有以下场景:

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."

所以,我的问题是:是否有任何的、商务人士友好的方式来做到这一点?我的意思是,代码优化和清晰易懂的独立场景定义之间的平衡?

4

1 回答 1

3

我认为场景大纲很适合你。

于 2012-04-09T09:31:16.200 回答