使用 20+ 测试极长表格的指南必填字段,使用 Rspec / Cucumber
只是想获得一些关于如何测试包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想测试一下,当用户填写表单并按“提交”时,应用程序会根据提交的信息执行正确的操作,对吧?
假设您正在使用标准 Cuke + Webrat 组合开发 Rails 应用程序,您可以这样做:
这有帮助吗?
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:
Does that help?
我认为您确实希望测试实际填写所有字段,以确保所有字段实际出现在表单上并且接受有效数据。
假设有些字段是必填字段,有些字段是可选字段,我可能会进行三个测试:一个填写每个字段,一个仅填写必填字段,一个省略必填字段之一。如果看起来有用的话,也许第四个测试会涵盖提交根本没有填写任何字段的按钮。这应该可以确保您不需要太多字段,并且如果您稍后将模型更改为需要更多字段或更少字段,则可能会提醒您更改视图,并确保如果需要字段,您可以显示一条不错的错误消息失踪了。但您可以保存模型规格的各个现场要求。
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.