Test::Unit 在 Rails 中仍然相关吗?

发布于 2024-07-16 13:50:00 字数 246 浏览 8 评论 0原文

我正在以古老的方式学习 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 技术交流群。

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

发布评论

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

评论(5

绝不服输 2024-07-23 13:50:01

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.

甜心 2024-07-23 13:50:01

有很多人仍然喜欢 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.

月野兔 2024-07-23 13:50:00

世界变了! 检查并投票@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!

陪你搞怪i 2024-07-23 13:50:00
開玄 2024-07-23 13:50:00

只是想我会发布 2012 年的更新:

三个 main当前(仅需要一些小的修改即可与 Rails 3.2 一起使用)关于 RoR 的入门书籍,其中两本使用 Rspec(最多简短提及 Test: :Unit),其中一个甚至正在为下一版本<制定moar Rspec。 /a>,所以现在谁将是这场“战斗”的胜利者已经很清楚了,

请允许我有选择地引用 dhh:

当然,重要的是我们让人们进行测试,所以工具不应该太重要。

2014 年重温:

Minitest 现在已取代 Test::Unit 作为当前版本 Rails 中的默认设置。 就我个人而言,我觉得与它的前身相比,它值得仔细研究,原因有很多 -

  1. 它作为默认状态的状态
  2. 对水豚和硒的更好支持,很大程度上归功于像
  3. 轻量级
  4. 主要向后兼容 Test::Unit

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:

The important thing is of course that we get people testing, so tools shouldn't matter too much.

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 -

  1. Its status as a default
  2. Better support for capybara and selenium, a large part due to gems like this
  3. Relatively lightweight
  4. Mostly backward compatible with Test::Unit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文