Ruby on Rails 中的全栈测试选项
Rails 应用程序的全栈测试有很多选项。有些使用真正的浏览器,有些是无头的,有些根本不运行 javascript。
您使用或推荐哪些工具,为什么?
浏览器模拟器或自动化程序列表:
- Rails 对集成和功能测试的内置支持(无 JS)
- Webrat
- Webrat::selenium
- Selenium
- Celerity(通过 Culerity)
- Watir
- ...
测试 DSL 和框架列表:
- Rails 默认值(断言,...)
- Shoulda
- Cucumber
- Capybara(多个浏览器模拟器的统一 DSL)
- ...
There are quite a number of options for Full-Stack testing of Rails applications. Some use real browsers, some are headless, some don't run javascript at all.
Which tools do you use or recommend and why?
List of browser simulators or automators:
- Rails built-in support for integration and functional tests (no JS)
- Webrat
- Webrat::selenium
- Selenium
- Celerity (through Culerity)
- Watir
- ...
List of testing DSLs and frameworks:
- Rails defaults (assertions, ...)
- Shoulda
- Cucumber
- Capybara (unified DSL for several browser simulators)
- ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
所有 Rails 应用程序都受益于单元和功能测试的良好覆盖,无论您使用 rspec 还是 Shoulda 等,这主要取决于个人喜好。我是
shoulda
的粉丝,主要是因为它提供的上下文块,使设置测试场景变得更容易、更清晰易懂。我认为不需要浏览器模拟器/自动化程序,除非您的应用程序的 javascript 非常繁重。我建议只使用它们来测试 JavaScript,为此目的,驾驶真实的浏览器肯定比模拟更好。我现在正在开发的应用程序需要大量 JavaScript,我们使用
cucumber
以及watir
/firewatir
来运行我们的 Cucumber 测试firefox 用于我们网站上的 javascript 驱动功能。All rails applications benefit from a good coverage of unit and functional tests, whether you use rspec or shoulda etc, is mostly a matter of personal preference. I'm a fan of
shoulda
mostly for the context blocks it provides, making setting up test scenarios much easier and clearer to understand.I don't think browser simulators/automators are needed unless your application is quite javascript heavy. I'd recommend only using them to test javascript, and for that purpose it's definitely better to go with driving a real browser than to simulate. The app I'm working on now is quite javascript heavy and we're using
cucumber
along withwatir
/firewatir
to run our cucumber tests in firefox for the javascript driven functions on our site.在过去的几年里,我在 Rails 职业生涯中使用了很多东西。
目前正在 JRuby 上开发一个相当大的 Rails 应用程序,具有非常可靠的测试覆盖率,我们的堆栈如下所示。
单元测试:
JSpec 覆盖率功能测试:
I have used a bunch of things during my Rails career over the last few years.
Currently working on a pretty large Rails app on JRuby with very solid test coverage and our stack looks like the following.
Unit Testing:
Functional Testing:
在我目前正在进行的项目中,为了测试完整的堆栈,我们使用 Cucumber 和水豚作为驱动程序。
前端的 javascript 非常繁重,我尝试了几个无头浏览器驱动程序(capybara-envjs 和 akephalos),但两者都错误地失败了在真实浏览器中通过的测试。
In the project I'm currently working on, for testing the full stack we're using Cucumber with capybara as the driver.
The front end is very javascript heavy, I've tried a couple of headless browser drivers (capybara-envjs and akephalos), but both were incorrectly failing tests that passed in a real browser.
我使用 Cucumber + Capybara 以及 selenium-webdriver 和rack-test 驱动程序的组合。 Capybara 很好地抽象了由 selenium-webdriver 驱动的浏览器内测试之间的差异,这些测试实际上可以测试 JavaScript 在浏览器中的工作情况,但需要一段时间才能运行并测试仅针对由 selenium-webdriver 生成的 HTML 运行的测试控制器/动作,运行速度更快,但不测试 JavaScript。这意味着相同的场景和步骤定义集可以在浏览器中运行,也可以不在浏览器中运行,而无需维护重复的步骤定义集。
I'm using Cucumber + Capybara with a combination of selenium-webdriver and the rack-test driver. Capybara does a good job of abstracting the difference between in-browser tests that get driven by selenium-webdriver for test that can actually test that the JavaScript works in a browser but take a while to run and test that just run against the HTML produced by the controller/action, which run much faster but don't test JavaScript. This means that the same set of scenarios and step definitions can be run in a browser or not without having to maintain duplicate sets of step definitions.