简体   繁体   English

我应该使用什么测试框架来测试我的Rails模型?

[英]What test framework should I use to test my Rails model?

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? 在Ruby社区中有许多测试框架,分别是:unittest, rspec ,hoa和maya,最适合测试我的Rails模型的测试框架是什么?

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. 非常感谢您的见解。

The differences mostly come down to personal taste. 差异主要取决于个人品味。 I recommend starting out with Test::Unit. 我建议从Test :: Unit开始。 There's plenty of documentation, and it's the default for Rails. 有很多文档,这是Rails的默认设置。 If you want to add Shoulda to the mix later, you can do that very easily. 如果您想稍后再将Shoulda添加到混音中,则可以轻松完成。

I also recommend using Factory Girl instead of fixtures. 我还建议使用Factory Girl代替灯具。 http://github.com/thoughtbot/factory_girl http://github.com/thoughtbot/factory_girl

Lots of people seem to love rspec. 很多人似乎都喜欢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. 有一本书即将出版,但是自从它宣布发布以来已经过去了一年,并将于今年12月发布。 The beta pdf version is ~$50 if you want it early. Beta pdf版本的价格约为50美元(如果您想早点购买的话)。

I suggest Test::Unit since you don't know it yet. 我建议使用Test :: Unit,因为您还不知道。 Good to know since you might read someone else's code and need to know about it. 很高兴知道,因为您可能会阅读别人的代码并且需要了解它。

I too would suggest starting with Test::Unit just to get a feel for it. 我也建议从Test :: Unit开始只是为了对此有所了解。 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. Shoulda可能是简单的Test :: Unit入门中比较容易的一种,因此它可能是下一个理想的选择。 On the other hand if you really like the syntax of RSpec you should definitely go with that. 另一方面,如果您真的喜欢RSpec的语法,则绝对应该这样做。

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 :) 如果适合您,仅坚持使用Test :: Unit也没有任何问题:)

Personally I'm a fan of the Shoulda + Factory Girl combo. 我个人是Shoulda + Factory Girl组合的粉丝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM