【发布时间】:2011-06-18 17:23:24
【问题描述】:
上下文:我正在尝试在 Ruby on Rails 环境中使用 Capybara/Steak 进行集成测试来练习 BDD,所以这将是我使用的示例,但这个问题是关于 BDD 的一般问题最佳做法。
假设我有一个像这样的(诚然广泛的)用户故事:
Feature:
As an administrator
I should be able to manage my products
我一直在研究 Rails 3 的 ActiveAdmin gem,它允许您使用简单的 DSL 创建复杂的管理界面。虽然节省时间的潜力很大,但我也害怕将这么多功能卸载到第三方代码而不进行测试。
但是,我被告知您通常只需要测试您自己编写的代码。所以,按照这个逻辑,我只需要测试ActiveAdmin 是否正确集成,因为这是我实际编写的唯一代码。对此进行测试的基本场景可能是:
Scenario:
Given I have 20 products
When I visit the product index page
Then I should see 20 products.
这是ActiveAdmin 提供的开箱即用功能。因此,我可以使用ActiveAdmin 的文档进行基本安装并创建产品管理页面,并且该方案将通过。
当然,那我也整合了大量的其他场景,比如:
Given I have 20 products
And my products include Apples, Bananas, and Berries
When I sort my products by name
Then Apples, Bananas and Berries should be on the first page in that order.
Given I have 20 products
And my products include Apples, Bananas, and Berries
When I type 'ap' into the Filter by Name field
Then I should see "Apples"
And I should not see "Bananas"
等等。等等
据推测,这些已经由ActiveAdmin 测试过,因此我不需要再次测试它们,即使它们对我的应用程序至关重要。所以我想我已经完成了,可以继续使用另一个功能(?)。
TL;DR:我的基本问题是,我是否应该为排序和过滤等关键功能编写场景,即使它们已经由外部库提供并且我已经测试了我的应用程序与该库的集成?
【问题讨论】:
标签: testing tdd integration-testing bdd