Rails 集成测试

发布于 2024-10-09 12:06:16 字数 255 浏览 0 评论 0 原文

我正在寻找为已经构建的 Rails 3 应用程序设置一堆集成测试。 该应用程序是使用 Rails 3 和 Ruby 1.9.2 构建的。我看过 Capybara、Cucumber 和 RSpec 2 的推荐,但我不确定它们各自的优点是什么。

我还注意到它们似乎紧密地联系在一起。我看到的帖子似乎总是谈论将 Capybara 与 Cucumber 一起使用,或将 Rspec 与 Cucumber 一起使用。

它们各自的优点/缺点是什么?是否存在某些组合效果最好?

I'm looking to set up a bunch of integration tests for an Rails 3 app that is already built.
The app is built with Rails 3 and Ruby 1.9.2. I've seen recommendations for Capybara, Cucumber and RSpec 2 but I'm not sure what the advantages of each are.

I've also noticed that they seem to be closely tied together. The post I've seen always seem to talk about using Capybara with Cucumber, or using Rspec with Cucumber.

What are the advantages/disadvantages for each of them? Are there certain combinations that work best together?

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

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

发布评论

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

评论(2

酷到爆炸 2024-10-16 12:06:16

所有这些测试工具都属于测试环境的不同部分。

如果您想设置集成测试,那么您应该使用Cucumber,因为它没有真正的替代方案。 Cucumber 旨在轻松进行行为驱动开发,但即使您不使用 BDD,它也非常适合集成测试。

Capybara 使命宣言是“旨在支持所有浏览器模拟器的 webrat 替代方案”。因此,要模拟浏览器部分(http 请求、DOM 操作等),您有两种选择 Webrat 或 Capybara。黄瓜与它们两者融合得很好。事实上,它会检测您的系统中安装了哪一个,并默认使用它。

另一边是Rspec。 Rspec 不是用于集成测试的工具,而是用于单元测试(使用 BDD 方法)的工具。在 http://www.pragprog.com/titles/achbd/the-rspec-书上解释得很清楚。 Cucumber 处于应用程序行为的外圈,而 rspec 处于类行为的内圈。 rspec 的替代方案是经典的 Test::Unit 类。

有关更多信息,请参阅:

All these test tools fall in different parts of the testing environment.

If you want to set up integration tests, then you should use Cucumber because it has no real alternative. Cucumber is designed to easy Behaviour Driven Development but even if you don't BDD it is perfect for integration testing.

Capybara mission statement is "webrat alternative which aims to support all browser simulators". So to simulate the browser part (http request, DOM manipulation, etc) you have two alternatives Webrat or Capybara. Cucumber integrates fine with both of them. In fact it detects which one you have installed in your system and by default uses it.

On the other side is Rspec. Rspec is not a tool for Integration Testing but for Unit Testing (with a BDD approach). In http://www.pragprog.com/titles/achbd/the-rspec-book it is explained very clearly. Cucumber is in an outer circle of application behaviour and rspec is in an inner circle of class behaviour. The alternative to rspec is classic Test::Unit classes.

For more information see:

御守 2024-10-16 12:06:16

总之,使用所有三个

使用RSpec...

  • ...单独测试模型、控制器和助手中的方法。
  • 也称为单元测试。

使用Cucumber...

  • ...来测试应用程序的高级功能。
  • 也称为集成测试。验证所有部分是否协同工作。
  • 适合从用户的角度进行测试。

Capybara 与 Cucumber 结合使用...

  • ...像用户通过浏览器一样导航您的应用程序。
  • ...用于测试您的视图包含用户期望看到的内容。

In summary, use all three.

Use RSpec...

  • ...for testing methods in your models, controllers, and helpers in isolation.
  • Also known as Unit testing.

Use Cucumber...

  • ...for testing high level features of your application.
  • Also known as integration testing. Verifies that all the pieces work together.
  • Good for testing from a user's perspective.

Use Capybara with Cucumber...

  • ...for navigating your app like a user would through the browser.
  • ...for testing your views contain the content that a user would expect to see.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文