集成与验收测试...什么是黄瓜/牛排?

发布于 2024-09-29 09:57:28 字数 135 浏览 7 评论 0原文

对于 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 技术交流群。

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

发布评论

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

评论(1

冷默言语 2024-10-06 09:57:29

首先,关于术语的说明:术语集成测试在 TDD 社区中有点模糊。根据您是来自 Java 还是 Rails(使用 Test::Unit),您可能会理解不同的东西。在 Rails(使用 Test::Unit)中,集成测试是测试整个堆栈的测试,而功能测试是测试控制器的测试。 Java 社区中的大多数人(至少根据我的观察)会认为事实恰恰相反。我个人更喜欢将端到端测试称为“验收测试”,而涉及系统多个层(但不是所有层)的测试——“集成测试”。总而言之,这很大程度上取决于您所处的文化。

至于 Cucumber 和 Steak,这两个框架都允许称为行为驱动开发(简称 BDD)的开发风格。关键是您有两个级别的测试:

  • 端到端测试,通过整个堆栈来测试您的测试 - 它们模拟浏览器,通过您的控制器并访问数据库。黄瓜和牛排适合这个利基市场。
  • 单元测试,单独测试一小部分功能(通常是单个类,模拟其协作者)。这就是 RSpec 的用武之地。

在 BDD 中,您从失败的端到端测试(亲切地称为“上档”)开始,然后开始使用 RSpec(“下档”)首先实现功能测试,直到得到最终结果:最终测试通过。这样,端到端测试将驱动您的单元测试,而单元测试又将驱动您的实现。主要好处是避免范围蔓延——您最终不会实现不需要的用户可见功能(因为您没有为其编写端到端测试)。

如果您想了解更多相关信息,我听说行为驱动开发维基百科文章令人惊讶好的。还有 RSpec 书。

因此,Cucumber 和 Steak 都是允许您以“高档”编写测试的框架。不同之处在于风格——Cucumber 让您用自然语言编写测试。这有几个好处。

  • 业务人员可以阅读测试——虽然您不能指望非程序员来编写它们,但它们在传达您打算做什么方面做得很好。您可以编写该功能(首先进行 Cucumber 测试)并将其展示给客户以获得一些反馈,了解这是否是他们真正想要的。我发现这非常有用。
  • Cucumber 功能可以更好地传达意图 - 由于您可以充分利用英语(或任何语言)的全部功能,因此您可以传达为什么此功能相关以及<强>如何用户实现他们的目标,而 Ruby 不允许您这样做。
  • Cucumber 有助于发现无处不在的语言——该领域包含许多在与客户的对话中频繁出现的术语。 Cucumber 允许您在开始实现该功能之前发现并捕获它们。这都是测试驱动的。
  • 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:

  • End-to-end tests, which test your through the full stack -- they simulate a browser, go through your controllers and hit the database. Cucumber and Steak fit this niche.
  • Unit tests, which test a small bit of functionality in isolation (usually a single class, mocking its collaborators). This is where RSpec fits.

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.

  • Tests are readable by the business people -- while you cannot expect non-programmers to write them, they do a great job in communicating what you intend to do. You can write the feature (the Cucumber test first) and show it to the customer to get some feedback on whether this is what they actually want. I've found this very useful.
  • Cucumber features communicate intent better -- since you get to use the full power of the English language (or any, really), you can communicate why this feature is relevant and how the users accomplish their goal on a level that Ruby won't allow you to.
  • Cucumber helps discovering the ubiquitous language -- the domain includes a lot of terms that fly around in the conversations with the customers. Cucumber allows you to discover and capture them before you start implementing the feature. And it's all test-driven.
  • Cucumber features are somewhat higher-level, which makes the features (but not the step definitions) more independent of the interface. This way if the interface needs changing, you won't have to rework the features.

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.

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