哪些测试工具在 Ruby 中做什么?
我的意思是,哪些工具用于单元测试,哪些工具用于 BDD,是否有明显的区别?
我刚刚从 C# 学习 Ruby,我熟悉的工具有用于纯单元测试/TDD 的 xUnit 风格,以及用于 BDD/集成测试的 Cucumber/SpecFlow。当然,如果愿意,您可以使用单元测试工具进行集成测试。
我遇到的 Ruby 主要测试工具是 Test::Unit、RSpec 和 Cucumber(显然还有更多工具,但这些工具似乎是最受欢迎的,因此可能是一个不错的选择)。
我并不是在这里寻找一长串工具 - 如果我错过了一个主要竞争者,请告诉我,但我宁愿在这个阶段保持简单,而不是开始使用带有 Library X 扩展的“Tool Z beta”在 MegaChode 平台或其他平台上运行。毕竟,我只是一个可怜的、困惑的.Net 人!
很明显,Test::Unit 是为单元测试而设计的,而 Cucumber 是为 BDD 设计的。但我不确定 RSpec - 有些人似乎将其用作低级单元测试工具,而另一些人则将其用作更高级别的 BDD。与此同时,有些人似乎将 Test::Unit(和类似的)与 BDD 的附加库一起使用。
为了让您了解我的出发点,我认为您可以使用 BDD 工具编写更多功能性、可测试的规范(业务人员可能会理解),然后进行低级、以开发人员为中心的工作当您实现 Cuke(或其他)所需的功能时,使用单元测试工具进行 TDD。
在 Ruby 中是否有一种普遍接受的方法来完成这些事情,或者我是否需要忘记这样一个疯狂的概念并使用任何看起来可以完成工作的东西?
干杯, 授予
What I mean by that is, which tools are for unit testing, which for BDD, is there even a clear divide?
I'm just learning Ruby from C#, and the tools I'm familiar with there are xUnit-style for pure unit testing/TDD, and Cucumber/SpecFlow for BDD/integration testing. Of course, you can use unit testing tools for integration testing if you want to.
The main testing tools I've come across for Ruby are Test::Unit, RSpec, and Cucumber (there are obviously plenty more but these seem to be the most popular, and hence probably a good bet to start off with).
I'm not looking for a long list of tools here - if there's a main contender I've missed then please tell me, but I'd rather keep it simple at this stage than start using 'Tool Z beta with the Library X extensions running on the MegaChode platform' or whatever. I'm only a poor confused .Net guy, after all!
It's clear that Test::Unit was designed for unit testing, and Cucumber is for BDD. But I'm not sure about RSpec - some people seem to use it as a low-level unit testing tool, and others for higher-level BDD. At the same time, some people seem to use Test::Unit (and similar) with additional libraries for BDD.
To give you an idea of where I'm coming from, the way I see it is that you can write more functional, testable specifications (which a business guy might understand) with your BDD tool and then do low-level, developer-focussed TDD with your unit testing tool as you implement the functionality required for your Cuke (or whatever).
Is there a generally accepted way of doing these things in Ruby, or do I need to forget about such a crazy notion and use whatever seems to do the job?
Cheers,
Grant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为大多数 Rubyists 已经标准化了 RSpec 而不是 Test::Unit 来进行测试。如果您正在开发 Rails 应用程序,则可以使用 RSpec-Rails 和 Cucumber,您可以在其上分层。
获取 Rspec 书籍的副本 @ http://www.pragprog.com/标题/achbd/the-rspec-book
I think most Rubyists have standardized on RSpec rather than Test::Unit for testing. If you're doing Rails apps, there is RSpec-Rails and then Cucumber you can layer on top of it.
Grab a copy of The Rspec Book @ http://www.pragprog.com/titles/achbd/the-rspec-book
MiniTest
包含 xUnit 和 spec 风格的测试接口(能够将它们组合在同一个文件中)。自 Ruby2.2 起,它就作为标准 gem 的一部分包含在内。
两者都可以包含在同一个文件中,这样可以轻松地在样式或其他测试工具(例如 RSpec 和 Test::Unit)之间进行转换
MiniTest 还包含一个模拟框架(尽管我更喜欢 rr)
MiniTest
contains both an xUnit and spec style testing interface (with the ability to combine them both in the same file).It is included as part of the standard gems since Ruby2.2.
Both can be included in the same file which makes it easy to convert between the styles or other testing tools like RSpec and Test::Unit
MiniTest also includes a mocking framework (although I prefer rr)