---
title: "什么是 BDD (行为驱动开发)？"
canonical: https://wavect.io/zh/glossary/bdd/
language: zh
description: "用业务方能读懂的语言写测试。然后让这些测试通过。"
image: "https://wavect.io/img/general/bak/open_graph_preview.jpg"
---

方法

# BDD

行为驱动开发

用业务方能读懂的语言写测试。然后让这些测试通过。

最近审阅: 2026-05-24 审阅人 [Kevin Riedl](/zh/team/kevin-riedl/) [wiki ↗](https://www.wikidata.org/wiki/Q139796365)

BDD 是把 [TDD](/zh/glossary/tdd/) 的测试语言改写成非工程师也能读懂的形式。Cucumber 之类工具用 Given/When/Then 格式，让一位产品经理也能签字。意图是让测试与它所验证的业务行为对齐，而不是与今天碰巧存在的实现对齐。

它在哪里真正有回报，举个实际例子：一个保险产品有一条规则，少于 30 天、且有有效保单的理赔自动通过。写成一个 Gherkin 场景（「Given 一份生效 30 天的保单，When 在保障窗口内提交理赔，Then 它自动通过」），产品负责人和合规审核人都能读它、确认它匹配真实规则，并在它发布之前抓住那个差一错误。那种共享语言的核对，正是 BDD 的全部价值，而它住在验收和集成层，那里正是「产品想要的」和「工程造出来的」之间的鸿沟、Bug 诞生的地方。

还有一项团队很晚才发现的维护成本。Gherkin 场景坐落在一层「Step 定义」之上，那是把每一行通俗英语映射到实际测试动作的胶水代码。那层胶水是真实的软件，必须随产品变化保持同步，而一个 Step 定义草率的大型 BDD 套件会变成它自己的维护负担，跑得慢、改起来脆。它的好处（一位利益相关者能读并签字确认行为）只有在确实有利益相关者去读时才抵得上那份开销。如果 Gherkin 由工程师写、由工程师读、从没被别人看过，你就是在为一个没有观众的翻译层付费。

诚实的取舍与常见错误：BDD 不是 TDD 的替代品，它是叠在上面的一层，而把它到处用就是那个错误。为一个琐碎函数写「Given 两个数，When 我把它们相加，Then 我得到和」是没有任何业务利益相关者会读的仪式。把 Gherkin 留给那些非工程师确实需要签字的测试，那条线以下用朴素的单元测试。像所有这些实践一样，BDD 是一段清醒的 [SDLC](/zh/glossary/sdlc/) 里的一个阶段，是为一个真实的沟通问题准备的工具，而不是一个为自身而采纳的流程。

// FAQ

## 常见问题

### BDD 还是 TDD？

不是二选一。BDD 在验收和集成层最有用，那里工程与产品需要一种共享语言。TDD 在单元测试层有用，那里的受众是其他工程师。大多数生产团队两者都用，只是用在不同的层。

### BDD 什么时候变成仪式多于价值？

在单元测试层，几乎总是如此。为一个把两个数相加的函数写「Given 一个带 X 的用户，When 他们做 Y，Then Z」就是仪式。把 Gherkin 留给那些业务利益相关者真的会去读的测试。

相关术语

- [TDD](/zh/glossary/tdd/)
- [Agile](/zh/glossary/agile/)
- [SDLC](/zh/glossary/sdlc/)

相关服务

- [软件开发](/zh/services/software-development/)

相关案例研究

- [Polity](/zh/case-studies/polity/)

相关指南

- [软件开发流程：从首次通话到完整交接](/zh/software-development-guide/software-development-process/)

聊聊

## Structured Data

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@id": "https://wavect.io/#organization",
      "@type": [
        "Organization",
        "ProfessionalService",
        "LocalBusiness"
      ],
      "employee": [
        {
          "@id": "https://wavect.io/team/kevin-riedl/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Kevin Riedl",
          "url": "https://wavect.io/team/kevin-riedl/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        },
        {
          "@id": "https://wavect.io/team/christof-jori/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Christof Jori",
          "url": "https://wavect.io/team/christof-jori/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        }
      ],
      "founder": [
        {
          "@id": "https://wavect.io/team/kevin-riedl/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Kevin Riedl",
          "url": "https://wavect.io/team/kevin-riedl/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        },
        {
          "@id": "https://wavect.io/team/christof-jori/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Christof Jori",
          "url": "https://wavect.io/team/christof-jori/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        }
      ],
      "legalRepresentative": [
        {
          "@id": "https://wavect.io/team/kevin-riedl/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Kevin Riedl",
          "url": "https://wavect.io/team/kevin-riedl/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        },
        {
          "@id": "https://wavect.io/team/christof-jori/#person",
          "@type": "Person",
          "jobTitle": "Managing Director",
          "name": "Christof Jori",
          "url": "https://wavect.io/team/christof-jori/",
          "worksFor": {
            "@id": "https://wavect.io/#organization",
            "@type": [
              "Organization",
              "ProfessionalService",
              "LocalBusiness"
            ]
          }
        }
      ],
      "name": "Wavect GmbH",
      "subjectOf": {
        "@id": "https://wavect.io/verified-claims.json#dataset",
        "@type": "Dataset",
        "creator": {
          "@id": "https://wavect.io/#organization",
          "@type": [
            "Organization",
            "ProfessionalService",
            "LocalBusiness"
          ]
        },
        "description": "A machine-readable registry of quantitative and qualitative claims published by Wavect, with review dates, localized page appearances and public third-party citations where available.",
        "inLanguage": "en",
        "isAccessibleForFree": true,
        "license": "https://creativecommons.org/licenses/by/4.0/",
        "name": "Wavect verified publication claims",
        "url": "https://wavect.io/verified-claims.json"
      },
      "url": "https://wavect.io/"
    },
    {
      "@id": "https://wavect.io/team/kevin-riedl/#person",
      "@type": "Person",
      "jobTitle": "Managing Director",
      "name": "Kevin Riedl",
      "sameAs": [
        "https://www.wikidata.org/wiki/Q139796365",
        "https://www.linkedin.com/in/wsdt",
        "https://github.com/wsdt"
      ],
      "url": "https://wavect.io/team/kevin-riedl/",
      "worksFor": {
        "@id": "https://wavect.io/#organization",
        "@type": [
          "Organization",
          "ProfessionalService",
          "LocalBusiness"
        ]
      }
    },
    {
      "@id": "https://wavect.io/team/christof-jori/#person",
      "@type": "Person",
      "jobTitle": "Managing Director",
      "name": "Christof Jori",
      "sameAs": [
        "https://www.wikidata.org/wiki/Q139796367",
        "https://www.linkedin.com/in/jocr77/",
        "https://github.com/jo-chris"
      ],
      "url": "https://wavect.io/team/christof-jori/",
      "worksFor": {
        "@id": "https://wavect.io/#organization",
        "@type": [
          "Organization",
          "ProfessionalService",
          "LocalBusiness"
        ]
      }
    },
    {
      "@id": "https://wavect.io/#website",
      "@type": "WebSite",
      "inLanguage": [
        "en",
        "de",
        "es",
        "zh"
      ],
      "name": "Wavect",
      "potentialAction": {
        "@type": "SearchAction",
        "query-input": "required name=search_term_string",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "https://wavect.io/search/?q={search_term_string}"
        }
      },
      "publisher": {
        "@id": "https://wavect.io/#organization",
        "@type": [
          "Organization",
          "ProfessionalService",
          "LocalBusiness"
        ]
      },
      "url": "https://wavect.io/"
    }
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@id": "https://wavect.io/zh/glossary/bdd/#term",
      "@type": "DefinedTerm",
      "alternateName": [],
      "description": "用业务方能读懂的语言写测试。然后让这些测试通过。",
      "inDefinedTermSet": "https://wavect.io/zh/glossary/#termset",
      "name": "BDD",
      "termCode": "bdd",
      "url": "https://wavect.io/zh/glossary/bdd/"
    },
    {
      "@id": "https://wavect.io/zh/glossary/bdd/#webpage",
      "@type": "WebPage",
      "about": {
        "@id": "https://wavect.io/#organization",
        "@type": [
          "Organization",
          "ProfessionalService",
          "LocalBusiness"
        ]
      },
      "author": {
        "@id": "https://wavect.io/team/kevin-riedl/#person",
        "@type": "Person",
        "name": "Kevin Riedl",
        "url": "https://wavect.io/team/kevin-riedl/"
      },
      "dateModified": "2026-05-24",
      "description": "用业务方能读懂的语言写测试。然后让这些测试通过。",
      "headline": "BDD",
      "inLanguage": "zh",
      "isPartOf": {
        "@id": "https://wavect.io/#website",
        "@type": "WebSite"
      },
      "lastReviewed": "2026-05-24",
      "mainEntity": {
        "@id": "https://wavect.io/zh/glossary/bdd/#term"
      },
      "mentions": [
        {
          "@id": "https://wavect.io/#organization",
          "@type": [
            "Organization",
            "ProfessionalService",
            "LocalBusiness"
          ]
        }
      ],
      "name": "BDD",
      "reviewedBy": {
        "@id": "https://wavect.io/team/christof-jori/#person",
        "@type": "Person",
        "name": "Christof Jori",
        "url": "https://wavect.io/team/christof-jori/"
      },
      "speakable": {
        "@type": "SpeakableSpecification",
        "cssSelector": [
          ".gls-single__h1",
          ".gls-single__tldr"
        ]
      },
      "url": "https://wavect.io/zh/glossary/bdd/"
    },
    {
      "@type": "BreadcrumbList",
      "itemListElement": [
        {
          "@type": "ListItem",
          "item": "https://wavect.io/zh/",
          "name": "首页",
          "position": 1
        },
        {
          "@type": "ListItem",
          "item": "https://wavect.io/zh/glossary/",
          "name": "技术、产品与合作模式术语表",
          "position": 2
        },
        {
          "@type": "ListItem",
          "item": "https://wavect.io/zh/glossary/bdd/",
          "name": "BDD",
          "position": 3
        }
      ]
    }
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不是二选一。BDD 在验收和集成层最有用，那里工程与产品需要一种共享语言。TDD 在单元测试层有用，那里的受众是其他工程师。大多数生产团队两者都用，只是用在不同的层。"
      },
      "name": "BDD 还是 TDD？"
    },
    {
      "@type": "Question",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "在单元测试层，几乎总是如此。为一个把两个数相加的函数写「Given 一个带 X 的用户，When 他们做 Y，Then Z」就是仪式。把 Gherkin 留给那些业务利益相关者真的会去读的测试。"
      },
      "name": "BDD 什么时候变成仪式多于价值？"
    }
  ],
  "speakable": {
    "@type": "SpeakableSpecification",
    "cssSelector": [
      ".faq-question",
      ".faq-answer"
    ]
  }
}
```
