0

我正在寻找一些背景信息来阐明功能场景之间的区别。

说,我有一个文件use_administration.feature

Feature: Use administration area

  So that I can administrate the application
  As an administrator
  I can visit the administration area

  Scenario: Get a login form
    Given I am not logged in
    When I visit the administration dashboard
    Then I should see a login-form

  Scenario: Access the Dashboard
    Given I am not logged in
    And there is a user "admin@example.com" with password "password"
    When I log in with username "admin@example.com" and password "password"
    Then I should see a dashboard

我会认为这些场景的定义非常明确。

但是,当查看另一个时Feature,问题变得更加清晰

Feature: Manage campings

  So that a writer can manage her campings
  As a logged in writer
  I want to update and delete campings

  Scenario: Logged in writer can create a new camping
    Given I am administrator
    And no campings on the campings listing
    When I create a Camping named "Beautifull Green"
    And I visit the "Campings" administration page
    Then I should see a camping "Beautifull Green"

  Scenario: Logged in writer sees own campings dashboard
    Given I am administrator
    And I have a camping "Beautifull Green"
    When I visit the administration dashboard
    Then I should see a panel titled "My Campings"
    Then I should see camping "Beautifull Green"

  Scenario: Logged in writer can update campings
    Given I am administrator
    And I have a camping "Beautifull Green"
    When I visit the update page for "Beautifull Green"
    And I update the name to "updated!"
    And I visit the "Campings" administration page
    Then I should see a camping "updated!"

  Scenario: Logged in writer can update camping from dashboard
    Given I am administrator
    And I have a camping "Beautifull Green"
    When I visit the administration dashboard
    Then I should see the "edit"-link for "Beautifull Green"

这些场景中有很多重叠,因此可能应该是功能本身。请注意,重叠部分主要由共享步骤覆盖。然而仍然有很多重复。

我的主要问题是:什么时候是功能,什么时候是场景。有什么经验法则吗?是否有关于一个功能应该包含多少个场景的良好做法?还是我完全误解了整个话题?

4

1 回答 1

1

在我看来,这一切都与现实生活中的组织能力有关。如果你能用简单的英语清楚地描述场景,那就足够了。

让我们检查您的第二个功能。有很多问题。

  1. 用户角色是什么?作家还是管理员?您在一个功能中提到了它们。这是不可接受的。

  2. 描述格式有问题。这不是正确的英语。它应该是:

    In order to keep my campaigns up to date
    As a logged in writer
    I want to manage my campaigns
    

    或者

    As a logged in writer
    I want to manage my campaigns
    So that I can keep my campaigns up to date
    

    这里有一些注释

    • 您在场景中提到了 CRUD,但前面的描述仅用于更新和删除。
    • “管理活动”不是业务目标,而是活动。所以我用“让我的广告系列保持最新”来代替它。
  3. 场景中有“鉴于我是管理员”和“我有一个露营'Beautifull Green'”的重叠。那是不必要的。你应该用它Background来描述。例如:

    Background:
      Given I have logged in as an Administrator
      And I have a camping "Beautifull Green"
    

    这些将为您节省所有重复项。如果您想测试Create,只需使用另一个名称,相同的“Nice Red”。

  4. 场景标题太长。无需主题。您之前已经描述了用户和背景。标题可以是:

    Scenario: Create new campaign
      # description here
    Scenario: Update campaign
      # .....
    

希望这些帮助。

于 2012-12-06T12:49:24.897 回答