何时使用 MiniTest::Unit::TestCase 与 MiniTest::Spec?
我一直在使用 MiniTest 学习 TDD/BDD。我想要弄清楚的是我的代码的哪些部分应该使用 MiniTest::Unit::TestCase 进行测试,哪些部分应该使用 MiniTest::Spec 进行测试。
我理解单元测试和集成测试之间的区别,我似乎无法从网络上的示例中理解 TestCase 和 Spec 是否都是单元测试,或者 TestCase 是否用于单元测试和 Spec用于集成测试?
我是否应该将快速单元测试保留在 MiniTest::Unit::TestCase 类中,而将更长时间的集成测试(通常描述功能)保留在 MiniTest::Spec 期望中?这有关系吗,还是个人喜好问题?
I've been learning TDD/BDD using MiniTest. What I'm trying to figure out is what parts of my code should be tested with MiniTest::Unit::TestCase and which parts should be tested using MiniTest::Spec.
I understand the difference between unit testing and integration testing, what I can't seem to grasp from examples across the web is whether or not a TestCase and a Spec are both unit tests or if a TestCase is used for a unit test and a Spec used for integration testing?
Should I keep my quick unit tests in MiniTest::Unit::TestCase classes and longer integration testing, which more often describe features, in MiniTest::Spec expectations? Does it even matter, or is it a question of personal preference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是否使用 MiniTest::Unit (带有 断言) 与 MiniTest::Spec,取决于我为谁编写它们。
对于我自己编写的代码,没有任何“客户”要求,我会使用 MiniTest::Unit。这些测试对我来说很有意义,而且阅读起来简洁明了。
如果我为有需求列表的客户编写代码,我会使用 MiniTest::Spec。规范文件对于非程序员来说更容易阅读。
注意:MiniTest 去年进行了一次大修,因此一些模块名称发生了变化,但想法是相同的,MiniTest 支持更简洁或更详细的编写单元测试的方式。
Whether I use MiniTest::Unit (with assertions) vs. MiniTest::Spec, is determined by who I am writing them for.
For code I write myself, without any "customer" requirements, I'd use MiniTest::Unit. The tests make sense to me and reading them is terse and to the point.
If I'm writing code for a customer who has a list of requirements, I'd use MiniTest::Spec. The spec files are more readable to a non-programmer.
Note: MiniTest underwent an overhaul last year so some of the module names changed but the idea is the same, MiniTest supports a more terse, or more verbose, way of writing unit tests.