Test::Unit 在 Rails 中仍然相关吗?
我正在以古老的方式学习 Rails。 以阅读使用 Rails 进行敏捷 Web 开发(第 3 版)作为起点。 我目前正在学习测试测试章节。 我还知道其他 BDD 测试框架,例如 RSPec。 所以我想知道 RSpec、Cucumber 等框架是否应该取代了解/使用 Test::Unit 的需要? 它们本身是否相关并用于不同的目的?
更新:由于我是测试新手,我也很想获得关于哪些资源对我熟悉不同框架有用的反馈。
谢谢!
I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering if frameworks such as RSpec, Cucumber, Shoulda replace the need for knowing/using Test::Unit? Are they both relevant in their own right and used for different purposes?
UPDATE: Since I am new to Testing, I would also love to get feedback on what resources are useful to get my feet wet with different frameworks.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Rspec 是一个完全独立的测试框架。 Shoulda 是 Rails 内置框架 Test::Unit 的增强。 如果您使用 Shoulda,则您使用的是 Test::Unit,但具有更多功能和更简单、更易读的语法。
我尝试过 Rspec 和 Shoulda,对我来说,Shoulda 轻而易举地获胜。 我更喜欢它。 但这可能是一个品味问题。
请注意,您可以将 Cucumber 与 Shoulda 一起使用 。
其他资源? 我推荐 ZenTest 和 RedGreen gems。 ZenTest 提供自动测试,让您可以在每次更改文件时自动运行测试。 这是一个很大的帮助。
关于固定装置与工厂,如果您需要设置一堆相互关联的对象,在其中测试双方或父子关系和/或测试多对多关系,则固定装置工作得更好。 事实上,我什至不确定工厂是否可以做到这一点。 所以不要忽视固定装置——它们有它们的用途。
Rspec is an entirely separate testing framework. Shoulda is an enhancement to Rails's built-in framework, Test::Unit. If you're using Shoulda, you're using Test::Unit but with more capabilities and simpler, more readable syntax.
I've tried Rspec and Shoulda and for me, Shoulda wins hands down. I like it way better. But that may be a matter of taste.
Note that you can use Cucumber with Shoulda.
Other resources? I recommend the ZenTest and RedGreen gems. ZenTest provides autotest, which lets you run your tests automatically every time you change a file. It's a big help.
Regarding fixtures vs. factories, if you need to set up a bunch of interrelated objects where you're testing both sides or a parent-child relationship and/or testing many-to-many relationships, fixtures work a lot better. Actually I'm not even sure you can do that with factories. So don't dismiss fixtures -- they have their uses.
有很多人仍然喜欢 Test::Unit,在某种程度上,这是个人喜好。 然而,总的来说,您会发现 RSpec 方面的活动要多得多。 真正酷的东西都是用 RSpec 和 Cucumber 完成的,所以如果你自己没有个人偏好,我可能会跳过 Test::Unit。 然而,您应该足够熟悉它,以便阅读其他人用它编写的测试,但我认为这不会成为问题。
There are a lot of people who still like Test::Unit, and to some extent, it's a personal preference. However, on balance, you will find far more activity on the RSpec front. The really cool stuff is all being done with RSpec and Cucumber, so if you don't have a personal preference yourself, I'd probably skip Test::Unit. You should, however, be familiar enough with it to read someone else's tests that are written with it, but I wouldn't foresee that ever being a problem.
世界变了! 检查并投票@prusswan
我认为 Test::Unit 仍然相关,尽管围绕 BDD 和其他测试工具有很多炒作。
话虽这么说,如果您愿意,您可以绕过学习 Test::Unit 并立即从 RSpec 和 Shoulda 之类的东西开始,但是有一些话要说,可以通过遵循《敏捷 Web 开发》书中的示例来了解BDD 的想法来自哪里。
我发现自己仍然在某些项目中使用 Test::Unit,因为它随 Rails 一起提供,并且仍然是一个非常出色的测试框架。
长话短说,我不认为它已经过时,但它不再是最前沿的。 BDD 是一种测试范式转变,尤其是当您开始使用 Cucumber 和 Webrat 时,但一旦您使用它,它就会非常棒。 Shoulda 是最容易过渡的,所以我会从 Test::Unit 开始,然后转向 Shoulda,然后尝试 RSpec 和 Cucumber。
您正在测试或至少有兴趣测试! 这是最好的部分。 最后,只要您满意,使用什么并不重要。
祝你好运!
The world has changed! Check down and upvote @prusswan
I think Test::Unit is still relevant even though there is a lot of hype surrounding BDD and other testing tools.
That being said, if you are up for it, you could bypass learning Test::Unit and start with something like RSpec and Shoulda right away, but there is something to be said about following through the examples in the Agile Web Development Book to see where the ideas from BDD came from.
I find myself still using Test::Unit for some projects since it comes with Rails and is still a very great testing framework.
So long story short, I don't think it's obsolete but it's not the cutting edge any more. BDD is a testing paradigm shift especially if you start using Cucumber and Webrat, but it's fantastic once you get into it. Shoulda is the easiest to make the transition to, so I would start with Test::Unit, then move to Shoulda, then Give RSpec and Cucumber a try.
You are testing or at least interested in testing! That's the best part. In the end it doesn't matter what you use as long as you are happy with it.
Good luck!
DHH 本人是 Test::Unit 的狂热用户之一,并且由于 RSpec / Cucumber 的相对复杂性而避免使用它们。
我尊重其背后的人,我完全支持实验,但 rSpec 和 Cucumber 的激增让我感到难过。
RSpec 在美学上冒犯了我,而且由于其比测试/单元增加的复杂性没有明显的好处。
除非你有客户阅读测试,否则黄瓜对我来说毫无意义。 为什么要构建一个特定于测试的英语解析器?
重要的是当然我们让人们进行测试,所以工具不应该太重要。 但增加的复杂性仍然让我感到不安。
“something.should be_true”对我来说很好地总结了美学论点出色地。 与“断言某事”相比,这个电话伤害了我的眼睛。
如果您有兴趣,请继续阅读这些推文的推特。
DHH himself is one of the avid users of Test::Unit and avoider of RSpec / Cucumber for their relative complexity.
I respect the guys behind it and I'm all for experimentation, but the proliferation of rSpec and Cucumber makes me sad.
RSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.
Cucumber makes no sense to me unless you have clients reading the tests. Why would you build a test-specific parser for English?
The important thing is of course that we get people testing, so tools shouldn't matter too much. But the added complexity still upsets me.
"something.should be_true" sums it up the aesthetic argument for me pretty well. That call hurts my eyes vs "assert something".
If you are interested, keep reading the twitter as of these twits.
只是想我会发布 2012 年的更新:
三个 main 和 当前(仅需要一些小的修改即可与 Rails 3.2 一起使用)关于 RoR 的入门书籍,其中两本使用 Rspec(最多简短提及 Test: :Unit),其中一个甚至正在为下一版本<制定moar Rspec。 /a>,所以现在谁将是这场“战斗”的胜利者已经很清楚了,
请允许我有选择地引用 dhh:
2014 年重温:
Minitest 现在已取代 Test::Unit 作为当前版本 Rails 中的默认设置。 就我个人而言,我觉得与它的前身相比,它值得仔细研究,原因有很多 -
Just thought I would post an update from 2012:
Out of the three main and current (usable with Rails 3.2 with no more than some minor modifications) introductory books on RoR, two of them are using Rspec (with at most a short mention for Test::Unit) and one of them is planning on even moar Rspec for the next edition, so it is clear who would be the winner of this "battle" for now
And allow me to selectively quote dhh:
Revisit in 2014:
Minitest has now superceded Test::Unit as a default in the current versions of Rails. Personally I feel it deserves a closer look compared to its predecessor for a number of reasons -