返回术语表
测试

TDD (Test-Driven Development)

A software development practice where tests are written before the actual code, following a cycle of: write a failing test, write minimal code to pass, then refactor.

定义

TDD follows the "Red-Green-Refactor" cycle: Red (write a test that fails), Green (write the minimum code to pass the test), Refactor (improve code while keeping tests green). This approach ensures every feature has test coverage, encourages simpler designs, and provides immediate feedback. TDD was popularized by Kent Beck as part of Extreme Programming (XP).

为什么重要

Teams practicing TDD report 40-90% reduction in bug density. TDD creates a comprehensive test suite as a byproduct of development, documents expected behavior, and enables confident refactoring. Studies show TDD code has fewer defects and better design.

示例

Before writing a password validator, a developer writes a test: expect(validatePassword("abc")).toBe(false). The test fails. They implement the minimum validation logic to pass, then refactor for clarity.

相关术语

TDDtest-driven developmentwhat is TDDTDD meaningtest first

使用diffray自动化代码审查

多智能体AI代码审查系统。自动发现bug、安全漏洞和架构问题。