我应该使用什么测试框架来测试我的 Rails 模型?
Ruby 社区提供了许多测试框架,即:unittest、rspec、shoulda 和 cana,什么会是测试我的 Rails 模型最合适的测试框架吗?
它们基本上具有相同的功能,即对我的模型进行单元测试吗?我什么时候应该使用哪个?使用其中一种而不使用另一种有什么好处?请帮我决定。
非常感谢您的见解。
With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model?
Do they basically have the same functionality, which is to unittest my model? When should I use which? What is the advantage of using one and not the other? Please help me decide.
Thank you very much for your insights.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
差异主要取决于个人品味。我建议从 Test::Unit 开始。有大量文档,并且它是 Rails 的默认文档。如果您想稍后将 Shoulda 添加到混合中,您可以非常轻松地做到这一点。
我还建议使用 Factory Girl 而不是固定装置。 http://github.com/thoughtbot/factory_girl
The differences mostly come down to personal taste. I recommend starting out with Test::Unit. There's plenty of documentation, and it's the default for Rails. If you want to add Shoulda to the mix later, you can do that very easily.
I also recommend using Factory Girl instead of fixtures. http://github.com/thoughtbot/factory_girl
很多人似乎喜欢 rspec。我很难在网上找到最新的(免费的)资源(教程)。应该有很好的截屏视频,但访问它们需要付费。有免费的截屏视频,但它们非常基础。一本书即将出版,但自宣布并于今年 12 月出版以来,可能已经有一年了。如果您想早点购买,beta pdf 版本的价格约为 50 美元。
我建议 Test::Unit 因为你还不知道它。很高兴知道,因为您可能会阅读其他人的代码并且需要了解它。
Lots of people seem to love rspec. I had a hard time finding recent (and free) resources (tutorials) online on it. There are supposed to be good screencasts, but there's fee to access them. There are free screencasts, but they're very basic. There's a book coming out, but it's been probably a year since it's announced and due out this December. The beta pdf version is ~$50 if you want it early.
I suggest Test::Unit since you don't know it yet. Good to know since you might read someone else's code and need to know about it.
我也建议从 Test::Unit 开始,只是为了感受一下它。然后看看其他一些框架,看看你最喜欢哪个。 Shoulda 可能是从普通 Test::Unit 开始的最容易开始的地方之一,所以它可能是接下来查看的理想位置。另一方面,如果您真的喜欢 RSpec 的语法,那么您绝对应该选择它。
关于这个话题的争论不断,但问题是,你使用什么并不重要,只要你进行某种形式的测试即可。如果适合您的话,坚持使用 Test::Unit 也没有什么问题:)
就我个人而言,我是 Shoulda + Factory Girl 组合的粉丝。
I too would suggest starting with Test::Unit just to get a feel for it. Then take a look a look at some of the other frameworks and see what you like best. Shoulda is probably one of the easier ones to get started with coming from plain Test::Unit so it might be an ideal place to look next. On the other hand if you really like the syntax of RSpec you should definitely go with that.
Wars get waged over this topic, but the thing is it doesn't really matter what you use, as long as your doing some form of testing. Also there is nothing wrong with just sticking with Test::Unit if that suits you :)
Personally I'm a fan of the Shoulda + Factory Girl combo.