Voltar ao glossario
Testing

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.

Definicao

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).

Por que e importante

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.

Exemplo

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.

Termos relacionados

TDDtest-driven developmentwhat is TDDTDD meaningtest first

Automatize Code Review com diffray

Sistema de IA multi-agente para code review. Encontra bugs, vulnerabilidades de seguranca e problemas de arquitetura automaticamente.