在 Rails 中使用 Minitest
最近,我读了很多关于Minitest的文章。我真的很喜欢超轻量级测试框架的想法。我决定在最近的一个项目中用它替换 rspec,但没能让它全部正常工作。我的问题是
a) 在我的验收/集成测试中获取命名路由(rspec 和 test::unit 似乎自动包含它们,但不与 minitest 一起使用),
b) 而且 Rails 整体上缺乏采用让我感到不安(每个人似乎都在使用 rspec,尽管它更多地用于 gems/库)。
当 rspec 在测试 Rails 应用程序方面占据主导地位时,是否值得使用 minitest?
Recently, I've read quite a few articles about Minitest. I really like the idea of a super lightweight test framework. I decided to replace rspec with it in a recent project and have had no luck getting it all to work. My problems are
a) getting named routes in my acceptance/integration tests (rspec and test::unit seem to automatically include them but no go with minitest),
b) and the overall lack of adoption in rails makes me uneasy (everyone seems to be using rspec though it's used more with gems/libraries).
Is it worth using minitest when rspec has the main dominance with testing rails applications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我是 minitest-rails 的作者。从你最初提出这个问题到现在,事情已经发生了很大的变化。我的回答假设您正在使用 minitest-rails。
命名路由
如果您使用的是 minitest-rails,那么这(现在)就可以了。您可以使用生成器来创建这些测试,或者自己编写它们。所有指定的路由都可以在您的验收/集成测试中使用。
采用
我认为,随着 Rails 4 的临近,我们将继续看到人们越来越关注将 Minitest 与 Rails 结合使用。
值得吗?
我认为现在开始 Minitest 是完全值得的。 Minitest 目前正在进行大量活动。它也与最近对快速测试的关注非常吻合。但这实际上取决于您的应用程序和团队动态。
I'm the author of minitest-rails. Things have changed a lot from the time you originally asked this to now. My answer assumes you're using minitest-rails.
Named Routes
If you are using minitest-rails this just works (now). You can use the generators to create these tests, or write them yourself. All the named routes are available in your acceptance/integration tests.
Adoption
I think we will continue to see increased attention on using Minitest with Rails as we get closer to Rails 4.
Worth it?
I think starting with Minitest now is totally worth it. There is tremendous activity going on in Minitest right now. It aligns nicely with the recent focus on fast tests as well. But it really depends on your app and team dynamics.
我最近将一个应用程序从 Rspec 切换到 Minitest &这是非常值得的。测试运行速度快得多,语法鼓励更智能、更精简的代码,&不知何故,我现在对套件更有信心了(工作中的魔力减少了)。
改进延伸到集成/验收测试,我发现 Minitest with Capybara 更具可读性和可操作性。比黄瓜简单(而且脆性要小得多)。
下面是一个帮助文件,它应该是您获取单元、功能和功能所需的全部内容。使用规范语法与 Minitest 一起运行的集成测试。这是基于@tenderlove & 的要点。大量阅读/实验。注释&以下注意事项。
注释
gem 'minitest'
对于获得一些更高级的 Minitest 功能(let
块等)是必要的。describe
块会引发错误I recently switched an application from Rspec to Minitest & it was well worth it. Tests run much faster, the syntax encourages smarter, leaner code, & somehow I just have more confidence in the suite now (less magic at work).
The improvement extends to integration/acceptance testing, I find Minitest with Capybara much more readable & straightforward than Cucumber (& much less brittle).
Below is a helper file that should be all you need to get unit, functional & integration tests running with Minitest using spec syntax. This was based on a gist by @tenderlove & a lot of reading/experimentation. Notes & caveats below.
Notes
gem 'minitest'
is necessary to get some more advanced Minitest functionality (let
blocks, etc.)describe
blocks in controller tests throw an error最近几天我做了一些工作,使用 minitest 测试 Rails 变得更加简单。请查看http://rawonrails.blogspot。 com/2012/01/better-way-of-testing-rails-application.html 了解更多信息。
I did some work last days to make testing Rails with minitest much straightforward. Please look at http://rawonrails.blogspot.com/2012/01/better-way-of-testing-rails-application.html to find more.
minitest-rails gem 使这一切变得简单。
The minitest-rails gem makes this easy.
Coding Ningja 的“MiniTest::Spec setup with Capybara in Rails 3.1”对于将 Minitest 与 Rails 集成有很大帮助。
http://code-ningja.posterous.com/73460416
Coding Ningja's "MiniTest::Spec setup with Capybara in Rails 3.1" helped a lot with integrating Minitest with Rails.
http://code-ningja.posterous.com/73460416