集成与验收测试...什么是黄瓜/牛排?
对于 Rails Web 应用程序的集成测试,我使用 Steak(类似于 Cucumber)。 Steak 的规格位于名为 spec/acceptance 的文件夹中。 Steak/Cucumber 现在正在进行集成或验收测试吗?我一直认为这是不同的东西。
For integration tests of my Rails web app I use Steak (something like Cucumber). The specs of Steak are in a folder named spec/acceptance. Are Steak/Cucumber now for integration or acceptance testing? I always thought that this is something different.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,关于术语的说明:术语集成测试在 TDD 社区中有点模糊。根据您是来自 Java 还是 Rails(使用 Test::Unit),您可能会理解不同的东西。在 Rails(使用 Test::Unit)中,集成测试是测试整个堆栈的测试,而功能测试是测试控制器的测试。 Java 社区中的大多数人(至少根据我的观察)会认为事实恰恰相反。我个人更喜欢将端到端测试称为“验收测试”,而涉及系统多个层(但不是所有层)的测试——“集成测试”。总而言之,这很大程度上取决于您所处的文化。
至于 Cucumber 和 Steak,这两个框架都允许称为行为驱动开发(简称 BDD)的开发风格。关键是您有两个级别的测试:
在 BDD 中,您从失败的端到端测试(亲切地称为“上档”)开始,然后开始使用 RSpec(“下档”)首先实现功能测试,直到得到最终结果:最终测试通过。这样,端到端测试将驱动您的单元测试,而单元测试又将驱动您的实现。主要好处是避免范围蔓延——您最终不会实现不需要的用户可见功能(因为您没有为其编写端到端测试)。
如果您想了解更多相关信息,我听说行为驱动开发维基百科文章令人惊讶好的。还有 RSpec 书。
因此,Cucumber 和 Steak 都是允许您以“高档”编写测试的框架。不同之处在于风格——Cucumber 让您用自然语言编写测试。这有几个好处。
缺点包括学习如何很好地应用它有点棘手,并且您必须编写更多内容(功能和步骤定义)。我发现,如果您已经这样做了一段时间,那么第二个并不是真正的问题,因为您获得了一系列可重用的步骤,可以让您更快地编写下一个功能。
另一方面,牛排更简单,而且是红宝石。你失去了使用英语的所有好处,但你可以写得更少,并且执行得更快(某种程度上)。
最重要的是,您可以使用两者来编写推动开发的端到端测试。
First, a note on the terminology: the term integration test is a bit vague in the TDD community. Depending whether you come from Java or Rails (with Test::Unit), you might understand different things by it. In Rails (with Test::Unit) integration tests are the tests that test your full stack, while functional tests would be the ones testing your controller. Most people in the Java community (at least by my observation) would think it is the other way around. I personally prefer to call the end-to-end tests acceptance tests, while tests that hit several layers of the system (but not everything) -- integration tests. All in all, that is pretty dependent on the culture your are in.
As for Cucumber and Steak -- both are frameworks that allow a development style known as Behavior-Driven Development (or BDD for short). The point is that you have two levels of tests:
In BDD, you start with a failing end-to-end test (lovingly know as the "upper gear"), and then you start implementing functionality test-first with RSpec (the "lower gear"), until you get the end-to-end test passing. This way the end-to-end test is driving your unit tests, which in turn are driving your implementation. The main benefit is avoiding scope creep -- you don't end up implementing user-visible functionality that you don't need (since you don't write an end-to-end test for it).
If you want more information on this, I've heard that the Behavior Driven Development Wikipedia article is surprisingly good. Also, the RSpec book.
So, both Cucumber and Steak are frameworks that allow you to write tests in the "upper gear". The difference is in the style -- Cucumber has you writing your tests in natural language. This has several benefits.
The downsides include that it is a bit tricky to learn how to apply it nicely and that you have to write a bit more (both features and step definitions). I've found that the second is not really a problem if you have been doing it for a while, since you get a body of reusable steps that allow you to write the next features faster.
Steak, on the other hand is simpler and it's Ruby. You loose all the benefits of using English, but you can write less and it will execute faster (somewhat).
In the bottom line, you use both to write the end-to-end tests that drive development.