使用 20+ 测试极长表格的指南必填字段,使用 Rspec / Cucumber

发布于 2024-08-12 15:14:43 字数 399 浏览 3 评论 0原文

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

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

#1 - 这是否足够?

问题 (此表格收集了大量个人联系信息/历史信息),您是否在 rspec 模型测试中编写了 20 多个测试,以确保正确考虑其中的每一个字段?

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

Just wanted to get some opinions on how to go about testing an extremely long form with 20+ required fields. It seems like my Cucumber scenario could be like 25 lines long if I tried to describe every field that need to be filled in (something like "And I fill in "Name:" with blah, And I fill in "Address" with foo, etc.).

If I simply say "When I provide all required information" as one of the Cucumber steps - it seems a little empty, but it keeps things clean. I then use Factory Girl to create a factory to represent a valid object, to test in cucumber steps and in model specs. Additionally I have model specs to make sure all required fields are included in the creation of the new object.

Question #1 - Does this suffice?

Question #2 - If I have 20+ required fields (this form collects a lot personal contact / history info), do you write a 20+ tests in your rspec model test to ensure each one of those fields is properly accounted for?

I know I cheated, asking 2 questions.. ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪我们做朋友吧 2024-08-19 15:14:43

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

假设您正在使用标准 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).

这有帮助吗?

You want to test that, when a User fills in the form and presses "Submit" that the app does the right thing based on the information submitted, right?

Assuming you are working on a rails app using the standard Cuke + Webrat combo, you can do:

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

Does that help?

囚我心虐我身 2024-08-19 15:14:43

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

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

I think you do want your test to actually fill in all the fields, to assure that all the fields are actually present on the form and will accept valid data.

Assuming that some fields are required and some are optional, I would probably have three tests: one that fills in every field, one that fills in only the required field, and one that omits one of the required fields. Maybe a fourth test to cover submitting the button with no fields at all filled in if it seems useful. That should assure you that you aren't requiring too many fields, and may alert you to change the view if you later change the model to require more fields or fewer fields, and assure that you can display a nice error message if a required field is missing. But you can save the individual field requirements for the model specs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文