Skip to content

Behavior-Driven Development (BDD)

一句话解释

BDD uses natural language (Given-当-然后) 到描述 expected behavior, 制作测试 readable 通过非-technical people.

用大白话说

BDD takes TDD and 制作它 更多 collaborative. 相反的 technical 测试 names, BDD uses natural language 格式那个每个人 — developers, testers, product owners — 能理解.

The 格式是 Given-当-然后:

  • Given 一些初始状态 (preconditions)
  • When 某事 happens (操作)
  • Then 这个应该 result (expected outcome)

For 示例: 'Given 用户是 logged in, 当它们点击登出, 然后它们应该 see 登录 page.' 这个读取如 specification, 不测试. business team 能读取 and 验证这些场景, and developers 编写 code 到制作它们通过.

Tools 如 Cucumber and Jest-Cucumber 执行这些 natural language 场景 as 实际测试.

示例

javascript
// BDD scenario (Cucumber/Gherkin syntax)
Given('a user is logged in', () => { /* setup */ });
When('they click logout', () => { /* action */ });
Then('they should see the login page', () => {
  expect(page.url()).toContain('/login');
});

Given-当-然后格式制作测试 readable as behavior specification.

常见混淆

  • 容易混淆的对象: TDD

    关键区别: BDD focuses on behavior 描述 in natural language for collaboration; TDD focuses on 测试-首先 coding 练习.

相关术语

相关资源

相关课程

  • BDD

    Behavior-driven development.

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表