BDD(行为驱动开发)是一种敏捷软件开发方法,其重点在于关注系统的期望行为和定义系统的行为。通常使用 BDD 框架(例如 Cucumber 或 SpecFlow)来编写自动化测试,并将其作为规格说明书的一部分。
另一方面,"Specifications by Example"是一种敏捷方法,其中重点是让业务利益相关者(如业务分析师、产品所有者等)使用示例作为规范的一部分来描述系统的行为。这些示例称为规格例子,通常被组织成故事或场景,以说明系统的应该如何运作。
虽然 BDD 和 “Specifications by Example” 都是基于例子和故事的规格方法,但是 BDD 更注重联合编码(编写测试驱动代码),而 “Specifications by Example” 更注重使用示例来支持对业务需求的共同理解。因此,它们在方法、工具和目标方面存在差异。
以下是使用 Cucumber 框架编写的 BDD 样例示例代码:
Feature: Calculator In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers
Scenario: Add two numbers Given I have entered 50 into the calculator And I have entered 70 into the calculator When I press add Then the result should be 120 on the screen
以下是通过规格示例编写的“规格之例’”样例示例代码:
As a user of the online store I want to add items to my cart So that I can purchase them later
Given that I am browsing products When I find a product I like Then I can add it to my cart
Given that I already have items in my cart When I add a new
上一篇:BDD参数化错误如何解决?