name: test-driven-development description: Test-driven development. Follow the RED-GREEN-REFACTOR cycle - write failing tests first, then write minimal code to pass, then refactor. Use when writing new features or fixing bugs.
Test-Driven Development Skill
Strictly follow the TDD RED-GREEN-REFACTOR cycle.
Core Principles
- Always Write Tests First - No production code without a failing test
- Minimal Implementation - Only write code to make the test pass
- Continuous Refactoring - Refactor immediately after tests pass
Workflow
RED Phase (Failing Test)
- Define the behavior to implement
- Write a test describing that behavior
- Run the test, confirm it fails
- Confirm failure is due to missing functionality, not test errors
GREEN Phase (Passing Test)
- Write the simplest code to make the test pass
- Don't over-engineer
- Run the test, confirm it passes
- Commit immediately
REFACTOR Phase
- Check for code duplication
- Check naming clarity
- Check single responsibility
- Run tests to confirm nothing broke
- Commit refactoring
Anti-Pattern Warnings
Avoid these behaviors:
- ❌ Writing code before tests
- ❌ Writing too many tests at once
- ❌ Refactoring before tests pass
- ❌ Skipping the failing test verification step
Test Naming Convention
test_[feature]_[scenario]_[expected_result]
Examples:
test_login_with_valid_credentials_returns_tokentest_login_with_invalid_password_returns_401