关于 Ruby 1.9.x 的测试框架是否达成共识?

发布于 2024-07-29 06:10:36 字数 1432 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

提笔落墨 2024-08-05 06:10:36

我使用 Rspec 已有一年左右的时间了。 我专门从 Test::Unit 切换过来,因为我可以以人类可读的方式打印正在测试的内容。

它读起来像散文。 这对我来说是很大的优势。 但与所有事情一样,结果会有所不同。

describe Model do
  it "should do what I want" do
    this.should == that
    it.should be_nil
    that.should_not be_true
  end
end 

另外,无论测试框架如何,您都应该考虑像 RCov 这样的覆盖工具。 它与 rspec 集成,并会告诉您代码哪里缺乏测试。

I have been using Rspec for a year or so. I switched from Test::Unit specifically because I could print in a human readable way what is being tested.

It reads like prose. Which is big plus for me. But as with everything results will vary.

describe Model do
  it "should do what I want" do
    this.should == that
    it.should be_nil
    that.should_not be_true
  end
end 

Also reguardless of test framework you should also think about a coverage tool like RCov. It integrates with rspec and will tell you where your code lacks testing.

寄居人 2024-08-05 06:10:36

有共识吗? 我想说不是。 社区对使用 TDD/BDD 的呼声很高,但即便如此,它也不是普遍的。 框架可能不如首先应用实践重要。

我相信 minitest 是 Test::Unit 的 1.9 替代品,它仅作为新库的包装器存在以实现向后兼容性。 我猜想,采取迷你测试特定的路线会更具前瞻性。

RSpec 是一种有些不同的做法:不太明显地受到“传统”xUnit 影响的框架的影响。 值得花一些时间看看你是否喜欢它。

还有Shoulda。 虽然我不知道它在 1.9 上是如何测试的:它更多的是 Test::Unit 的包装器/扩展,所以它可能会工作。

当然,乐趣还不止于此:一旦您选择了测试框架,您就会需要某种类型的模拟引擎。 或者更换数据固定装置。

在所有情况下,我想说,任何您可以找到定期更新证据的框架、一个开放的、人口稠密的社区和一个您不讨厌的 API 都可以完成这项工作。 无论你做出什么选择,你都不太可能在以后被击落。

Is there consensus? I'd say not. There's a strong community voice for using TDD/BDD but even then it's not universal. The framework is probably less important than applying the practice in the first place.

I believe that minitest is the 1.9 replacement for Test::Unit, which only exists as a wrapper around the new library for backward compatibility. I'd guess that taking the minitest-specific route would be more forward-looking.

RSpec is a somewhat different take: less obviously infused by the "traditional" xUnit-influenced frameworks. It's worth spending some time with to see if you prefer it.

There's also Shoulda. although I don't know how tested it is on 1.9: it's more of a wrapper/extension for Test::Unit, so it'll probably work, though.

Of course the fun doesn't stop there: once you've chosen a test framework you're going to want a mocking engine of some kind. Or a data fixture replacement.

In all cases, I'd say any framework for which you can find evidence of regular updates, an open, populated community and an API you don't hate will do the job. It's unlikely that you're going to be shot down later for having made whatever choice you do.

╰◇生如夏花灿烂 2024-08-05 06:10:36

RSpec 是《The Rails Way》等流行 Rails 书籍的共识。 恕我直言,优点是读起来像英语的测试、读起来像英语的输出格式以及即时匹配器。 缺点是速度慢,并且该库有时感觉“神奇”,即对于更熟悉 Ruby 和单元测试的编码人员来说太陌生。 RSpec 还提供 Cucumber 和 Gherkin,这些都是编写有助于客户接受的用户故事的方法。

MiniTest 内置于 Ruby 1.9 中。 恕我直言,优点是速度快,对于其他语言的编码人员来说非常容易读/写,并且测试使用与实际代码中使用的代码风格大致相同的代码风格。 MiniTest 的功能比大多数人知道的要多得多,例如 MiniTest Spec 具有类似于 RSpec 的 BDD 匹配器,MiniTest Mock 是一个模拟系统,MiniTest Benchmark 用于性能分析。

根据我个人的经验,构建 Rails 应用程序的人倾向于 RSpec,构建纯 Ruby 代码的人倾向于 MiniTest Unit、Spec、Mock、Benchmark 等。

RSpec is the consensus of popular Rails books like "The Rails Way". Pros IMHO are tests that read like English, output formats that read like English, and on-the-fly matchers. Cons are slow speed and the library sometimes feels "magical" i.e. too foreign to coders who are more familiar with Ruby and unit tests. RSpec also offers Cucumber and Gherkin, which are ways to write users stories that are useful customer acceptance.

MiniTest is built into Ruby 1.9. Pros IMHO are fast speed, very easy to read/write for coders of other languages, and tests that use much the same code style you'd use in your real code. MiniTest has much more than most people know, for example MiniTest Spec has BDD matchers akin to RSpec, MiniTest Mock is a mocking system, and MiniTest Benchmark is for performance profiling.

In my personal experience, people who build Rails apps tend toward RSpec, and people who build pure Ruby code tend toward MiniTest Unit, Spec, Mock, Benchmark, and so on.

神经大条 2024-08-05 06:10:36

我个人更喜欢 rspec。 我发现将测试重点放在行为上确实有助于我解决我想做的事情。

使用 rspec 去获取像 Factory Girl 或 Machinist 这样的东西来生成测试数据,不要使用固定装置。

据Mike所说,rspec项目相当活跃,每个版本的rails都会正常发布新版本,以帮助其跟上框架的发展。

I personally perfer rspec. I found that focusing my tests on behaviour really helped me get around what I was trying to do.

With rspec go and get something like Factory Girl or Machinist to generate your test data, don't use fixtures.

With regard to what Mike said, the rspec project is fairly active with new versions being released normally with each version of rails to help it keep up with the development of the framework.

妖妓 2024-08-05 06:10:36

RSpec 很好,但我认为最近 Ruby 1.9 附带的 Minitest 背后有很多讨论和动向。X。 它具有 RSpec 的许多优点,但更加精简和简洁。

RSpec is nice but I think recently there has been a lot of talk and movement behind Minitest which comes with Ruby 1.9.x. It has a lot of the niceties of RSpec but is much leaner and and concise.

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