gpt4 book ai didi

ruby-on-rails - 在 Rails 中,我应该在 capybara (或集成)测试中包含用户输入表单错误流吗?

转载 作者:行者123 更新时间:2023-11-28 20:15:03 27 4
gpt4 key购买 nike

Rails 支持多种类型的测试:

  • 模型测试
  • Controller 测试
  • 功能测试
  • 集成测试

并且,对于 capybara ,它还可以支持:

  • 验收/集成/功能(取决于作者)测试

在一些网站上,我看到这些验收/集成/功能测试应该只测试特定的流程,将边缘情况留给其他类型的测试。例如:

Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.

http://guides.rubyonrails.org/testing.html#integration-testing

While these are great for testing high level functionality, keep in mind that feature specs are slow to run. Instead of testing every possible path through your application with Capybara, leave testing edge cases up to your model, view, and controller specs.

http://robots.thoughtbot.com/how-we-test-rails-applications

但我也看到了类似的东西:

Your goal should be to write an integration test for every flow through your app: make sure every page gets visited, that every form gets submitted correctly one time and incorrectly one time, and test each flow for different types of users who may have different permissions (to make sure they can visit the pages they're allowed to, and not visit the pages they're not allowed to). You should have a lot of integration tests for your apps!

https://www.learnhowtoprogram.com/lessons/integration-testing-with-capybara

那么,这就是我的问题:在 Rails 中,我应该在 capybara (或集成)测试中包含用户输入表单错误流吗?

或者您认为编写 View 测试以测试是否存在 flash 消息、使用分配帮助程序通过 Controller 测试测试失败流以及仅通过验收/集成/功能测试测试成功流就足够了吗?

编辑接受的答案是由于评论。

最佳答案

用户输入表单错误由 Active Record validations 处理在 Rails 中。所以你可以用 unit tests 覆盖这些.但是这些类型的测试仅验证您的模型是否存在验证。除了允许您在另一种框架或语言中重新创建模型并仍然让您的测试通过之外,我不确定这些类型的测试提供了多少实用性。

关于ruby-on-rails - 在 Rails 中,我应该在 capybara (或集成)测试中包含用户输入表单错误流吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790291/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com