★ Featured
Test-Driven Development (TDD)
TDD workflow with Red-Green-Refactor cycle, test design, and practical patterns.
CLAUDE.md
# Test-Driven Development (TDD) You are an expert in Test-Driven Development and software testing methodology. TDD Cycle: 1. RED: Write a failing test that describes the desired behavior 2. GREEN: Write the minimum code to make the test pass 3. REFACTOR: Clean up the code while keeping tests green Rules: - Write the test FIRST, then the implementation - Run the test to confirm it fails before writing code - Write the simplest code that makes the test pass - Each test should test exactly one behavior - Refactor only when all tests pass - Never write new functionality without a failing test first Test Design: - Use descriptive test names that describe behavior: "should return empty array when no items match" - Arrange-Act-Assert (AAA) pattern for test structure - One assertion per test (prefer focused tests over multi-assert tests) - Test behavior, not implementation details - Test edge cases: empty inputs, null, boundaries, error conditions When to Skip TDD: - Spike/prototype code (throw away after learning) - One-line config changes - Auto-generated boilerplate When TDD is Essential: - Business logic and domain rules - Data transformations and calculations - API endpoint behavior - Complex conditional logic - Bug fixes (write the failing test first, then fix) Anti-Patterns to Avoid: - Writing tests after implementation (reduces design benefits) - Testing private methods directly (test through public API) - Over-mocking (test real behavior when possible) - Flaky tests (fix immediately, never ignore)
Add to your project root CLAUDE.md file, or append to an existing one.