SKILL.md
TDD Workflow Skill
Enforce TDD workflow and ensure proper execution of the Red-Green-Refactor cycle.
Trigger Conditions
- When starting a new feature implementation
- When starting a bug fix
- When starting refactoring
Phases
Phase 1: Red (Create test and confirm failure)
- Create/identify test file
- Naming convention: test_<feature>.py - Location: tests/ directory
- Design test cases
- Clearly define expected behavior - Consider edge cases - Test naming convention: test<feature><situation><expectedresult>
- Run test and confirm failure
``bash uv run pytest tests/test_<feature>.py -v ``
- User approval (required)
- Present test cases - Get approval before proceeding to next phase
Phase 2: Green (Minimal implementation)
- Create implementation file
- Focus only on making the test pass - Avoid over-engineering
- Run test and confirm success
``bash uv run pytest tests/test_<feature>.py -v ``
- Quality checks
``bash uv run ruff check --fix . && uv run ruff format . && uv run mypy . ``
Phase 3: Refactor
- Improve code
- Remove duplication - Improve readability
- Re-run all tests
``bash uv run pytest ``
File Mapping
| Implementation File | Test File |
|---|---|
src/auth.py |
tests/test_auth.py |
src/article.py |
tests/test_article.py |
src/services/user.py |
tests/test_user.py |
Test Naming Convention
test<feature><situation><expectedresult>
Examples:
testloginwithvalidcredentialsreturnssessiontestloginwithinvalidpasswordraiseserrortestcreateuserwithduplicateemailfails
Enforcement Rules
- If test file doesn't exist
- Request test file creation before starting implementation - Block implementation file edits
- If test is not failing (Red)
- Confirm test fails as intended - Explain that a test that doesn't fail is meaningless
- After test succeeds (Green)
- Suggest transition to refactoring phase - Check if additional test cases are needed
Quality Gates
- All tests must pass
- Coverage must meet standards
- No errors in static analysis
Instructions for Claude
When implementing a feature:
- Always ask: "Do you want me to follow TDD workflow?"
- If yes:
- First, write the test file - Show the test to the user - Run the test and confirm it fails - Get user approval before implementation - Implement the minimal code to pass - Run tests again - Refactor if needed
- Track progress:
- Mark each phase (Red, Green, Refactor) - Report test results at each phase