Rails 集成测试:减少执行时间
我想分享我的发现,并听取其他人关于减少 Rails 应用程序集成测试执行时间的成功和失败尝试(无论是“普通”测试,基于 Cucumber 或 RSpec)。
这个问题意味着测试涉及数据库、视图渲染,可能还涉及 JavaScript/AJAX。 Ei 测试不会存根/模拟应用程序的缓慢部分。
I want to share my finding and hear from others about successful and failed attepts to reduce execution time of integration tests of Rails applications (be it 'ordinary' tests, Cucumber- or RSpec-based).
The question implies that tests involve database, view rendering, and maybe JavaScript/AJAX. E.i. test don't stub/mock slow parts of the application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作者的回答。
我尝试了两件事:spork插件和内存数据库。我的开发配置:Ubuntu VirtualBox 托管在 Win7、Ruby 1.8.7、Rails 3、SQLite 上。
Spork 插件将我的测试的启动时间从 35 秒缩短到 2 秒秒。我总结了此处步骤,但 github 自述文件中对它们的描述已经足够好了。 这个帖子还描述了如何将其与 Guard 一起使用,以确保 spork 服务器在文件更改时重新启动。
我尝试使用内存数据库 减少执行时间。在某些情况下,它们可以将执行时间减少 10%,但创建模式的启动时间会增加 2 秒的开销。结果远远超出了我观察到的改善。所以我自己决定,改进是不值得的。
另外,我使用RVM将Ruby 1.8.7替换为1.9.2< /强>。它将执行时间从 58 秒减少到 42 秒。
结论:Spork 并用 1.9.2 替换 1.8.7 可以显着改善您的 TDD 体验。
Author's answer.
I tried two things: spork plug-in and in-memory database. My dev configuration: Ubuntu VirtualBox hosted on Win7, Ruby 1.8.7, Rails 3, SQLite.
Spork plug-in reduced launch time of my tests from 35 seconds to 2 seconds. I summarized here steps, but they are described in github readme good enough. This post also describes how to use it with Guard to ensure spork server restarting when files change.
I tried to use in-memory database to reduce execution time. They in some cases reduce execution time by 10%, but have 2 sec overhead to launchtime to create schema. And results very more then i could observe improvement. So I decided for myself that improvement is not worth the trouble.
Also I used RVM to replace Ruby 1.8.7 with 1.9.2. It reduced execution time from 58 to 42 seconds.
Conclusion: Spork and replacing 1.8.7 with 1.9.2 can significantly improve your TDD experience.