【问题标题】:Cucumber Length?黄瓜长度?
【发布时间】:2011-05-16 15:38:20
【问题描述】:

我正在为多步骤注册过程创建 Cucumber 测试,但对场景步骤的最佳实践有点不确定...

注册中有4个表格/页面。我应该在一个场景中循环通过 Given、When 和 Then 4 次,还是有更好的方法来组织它?

到目前为止,我已经...

Scenario: Company User
Given I am on the registration page
When I follow "Register as a supplier"
When I fill in the following:
  | user_email | test@test.com |
  | user_password | secret |
  | user_password_confirmation | secret |
And I press "Create login - Proceed to step 2"
Then I should see "Create Company Profile"
When I fill in the following:
  | company_name | Test Company |
  | company_description | Lorem |
  | company_telephone | 01928740436 |
  | company_email | info@agency.com |
And I press "Create company - Proceed to step 3"
Then I should see "Test Company office(s)"

【问题讨论】:

  • 如果这实际上不是狡猾的影射,我会非常失望。
  • 这篇文章的标题让我笑了:)
  • 这对我来说看起来不错,但如果它是我的代码,我可能会将所有表单位提取到一个步骤定义中,并且更通用,例如:“当我设置我的电子邮件和密码”和“当我填写我的公司信息”
  • This 应该会有所帮助。

标签: ruby-on-rails testing cucumber


【解决方案1】:

我认为 Andy Waite 给出了很好的建议,但不是像 step 1、step2 等通用名称。我会更具描述性:

When I register as a supplier with valid information
And I create company profile with valid information
And I ... with valid information
And I ... with valid information
Then I should see "Thank you for registering"

【讨论】:

    【解决方案2】:

    我建议有 4 个场景涵盖每个步骤的细节,例如:

    Given I am on step 2
    When I fill in the following:
      | company_name | Test Company |
      | company_description | Lorem |
      | company_telephone | 01928740436 |
      | company_email | info@agency.com |
    And I press "Create company - Proceed to step 3"
    Then I should see "Test Company office(s)"
    

    您可以在“鉴于我在第 X 步”的定义中隐藏任何必要但不相关的表单填写。

    您可能还应该有一个涵盖所有内容如何组合在一起的场景,例如:

    When I complete step 1 with valid information
    And I complete step 2 with valid information
    And I complete step 3 with valid information
    And I complete step 4 with valid information
    Then I should see "Thank you for registering"
    

    【讨论】:

    • 感谢大家的帮助。我已经精简了这个功能,并在幕后给了它一些大的“萌芽”步骤。
    【解决方案3】:

    我喜欢 Mark Irvine 的建议 - Cucumber 自动化的主要概念之一是编写对读者来说尽可能清晰的步骤。即使对于根本不是程序员的人,也应该绝对清楚测试在做什么。

    如果您有兴趣 - 您还可以阅读 Matt Wynne 的“The Cucumber Book - Behaviour-Driven-Development for testers and Developers”,了解更多良好实践。

    问候, 亚历克斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      相关资源
      最近更新 更多