【问题标题】:Guidance on testing extremely long form with 20+ required fields, using Rspec / Cucumber使用 Rspec / Cucumber 测试包含 20 多个必填字段的超长表单的指南
【发布时间】:2009-11-25 19:06:38
【问题描述】:

只是想就如何测试一个包含 20 多个必填字段的超长表单获得一些意见。如果我试图描述每个需要填写的字段,我的 Cucumber 场景似乎可能有 25 行长(比如“我用 blah 填写“姓名:”,然后用 foo 填写“地址”,等等)。

如果我只是说“当我提供所有必需的信息时”作为 Cucumber 步骤之一 - 它看起来有点空洞,但它可以让事情保持清洁。然后我使用 Factory Girl 创建一个工厂来表示一个有效的对象,在黄瓜步骤和模型规格中进行测试。此外,我有模型规范以确保所有必填字段都包含在新对象的创建中。

问题 #1 - 这是否足够?

问题 #2 - 如果我有 20 多个必填字段(此表单收集了很多个人联系/历史信息),您是否在 rspec 模型测试中编写了 20 多个测试以确保正确考虑这些字段中的每一个?

我知道我作弊了,问了两个问题.. ;)

【问题讨论】:

    标签: ruby-on-rails rspec cucumber


    【解决方案1】:

    您想测试一下,当用户填写表单并按下“提交”时,应用会根据提交的信息执行正确的操作,对吧?

    假设您正在使用标准 Cuke + Webrat 组合开发 Rails 应用程序,您可以这样做:

    Background: Login, go to really long form
      Given the user "Fred exists" # Factory a user into existance, something like @user = Factory(:user, :username => "Fred"
      And I am on the "Really long form" page # map "Really long form page" in /features/supposrt/paths.rb
    
    Scenario: Succesfully fill in really long form
      When I fill in the following: # This is defined in Webrat steps
      | field 1  | response 1  |
      | field 2  | response 2  |
    ...
      | field 19 | response 19 |
      | field 20 | response 20 |
    
      And I press "Save"
      Then I should see a "success" message # assert there is a div with the calss success. Could be an error message
      And "Fred" should have a valid set of attributes # because you defined @user, you can call whatever assertions you like here i.e. assert equal @user.username, "Fred" (I forget the correct syntax for doing this, but you get the idea).
    

    这有帮助吗?

    【讨论】:

      【解决方案2】:

      我认为您确实希望您的测试能够实际填写所有字段,以确保所有字段都实际出现在表单上并接受有效数据。

      假设有些字段是必需的,有些是可选的,我可能会进行三个测试:一个填写每个字段,一个只填写必填字段,一个省略一个必填字段。如果看起来有用,也许第四个测试涵盖提交没有填写任何字段的按钮。这应该确保您不需要太多字段,并且如果您稍后将模型更改为需要更多字段或更少字段,并且可能会提醒您更改视图,并确保您可以在必填字段时显示一个很好的错误消息不见了。但您可以保存模型规格的各个字段要求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-28
        • 1970-01-01
        相关资源
        最近更新 更多