【问题标题】:Best BDD practices for designing Cucumber scenarios for forms为表单设计 Cucumber 场景的最佳 BDD 实践
【发布时间】:2010-12-15 08:27:00
【问题描述】:

假设您有一个创建新用户的表单。 您如何编写 Cucumber 场景?

1.)

Given I am logged in as admin
When I create a new user
Then I should see "Successfully created user"

2.)

Given I am logged in as admin
When I go to Create new user
And I fill in "Name" with "Name111"
And I fill in "Password" with "Password111"
And I press "Create new user"
Then I should see "Successfully created user"

如果您选择 1.) 您在哪里记录用户的要求(用户应该有名称和密码)。我看到 BDD 是关于行为的,但在某些时候你和利益相关者必须指定用户应该拥有哪些属性,不是吗?

我对 BDD 很陌生,所以我很感激任何建议......

【问题讨论】:

    标签: ruby-on-rails tdd cucumber bdd


    【解决方案1】:

    您应该阅读Imperative vs Declarative Scenarios

    --阿斯拉克。黄瓜的创造者。

    【讨论】:

      【解决方案2】:

      您编写的场景相当低级。除非您实际上正在生产要出售的安全登录功能,否则我会坚持使用快乐的情况并进行单元/手动测试其余部分。如果您不这样做,您将创建如此多的场景,这将是一场维护噩梦。

      找出您正在创建的产品与所有类似产品的区别,然后将其作为场景的价值。然后它看起来像这样:

      Given Fred is logged in
      When Fred <does something>
      Then Fred should <get some really differentiating value>
      And <something else happens>
      

      坚持真正的高级功能,而不是基于表单的低级步骤。例如:

      Given there is already a question on BDD and Cucumber
      Given Peyote is logged in
      When Peyote proposes a question on BDD and Cucumber
      Then Peyote should see other questions on BDD and Cucumber.
      

      有一个称为“页面范式”的概念,您可以在其中创建一个包含页面或屏幕可以执行的所有低级步骤的类。然后,您可以从更高级别的 Cucumber 步骤装置中调用页面上的那些低级别步骤。

      您的企业将更多地参与此类场景。 BDD 的主要目的不是生成自动化测试,而是围绕场景进行对话,以便您可以找出哪里出了问题,以及在执行代码之前可以考虑哪些其他选项。自动化测试是一个很好的副产品。

      对话以及通过对话获得的学习是 BDD 与 ATDD(验收测试驱动开发)不同的原因。这就是为什么我们使用 Example、Scenario、Given、When、Then、Context、Event、Outcome 之类的语言,而不是 Test、SetUp、TearDown、Act、Arrange、Assert - 所以我们可以用同一种语言与业务、BA 和测试人员讨论这些问题。

      请参阅 Dan North's article on Deliberate Discovery 和他的博客的其余部分了解更多信息,祝 BDD 好运!

      【讨论】:

        【解决方案3】:

        任何一个都可以。使用#1,您将创建一个步骤来处理表格的填写。我更喜欢 #1 和 #2 的混合体,因为我经常使用场景大纲,例如:

        Background: 
         Given the following users exist:
           | email             | password        |
           | test@example.com  | testpassword23  |
           | test2@example.com | notthistime     |
           | test3@example.com | welcomeback     |
        
          @login @authentication
          Scenario Outline: Authentication
             Given I am on the new user session page
             When I login with "<s_email>" and "<s_password>"
             And I press "Login"
             Then I should see "<s_message>"
        
          Examples:
            | s_email           | s_password       | s_message                      |
            | test@example.com  | testpassword23   | Signed in successfully         |
            | test2@example.com | itriedreallyhard | Invalid email or password.     |
            | teOst@example.com | testpassword23   | Invalid email or password.     |
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-07
          • 1970-01-01
          • 1970-01-01
          • 2011-11-18
          • 2013-12-01
          • 1970-01-01
          相关资源
          最近更新 更多