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

发布于 2024-08-07 21:02:32 字数 233 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛起拖把扫天下 2024-08-14 21:02:32

差异主要取决于个人品味。我建议从 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

方圜几里 2024-08-14 21:02:32

很多人似乎喜欢 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.

べ繥欢鉨o。 2024-08-14 21:02:32

我也建议从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文