docs: Add comprehensive TDD requirements to CLAUDE.md
- Add detailed TDD workflow (Red-Green-Refactor) - Specify test-first approach as non-negotiable - Include testing requirements (85% coverage minimum) - Add test types and running instructions - List TDD anti-patterns to avoid - Provide example TDD session workflow Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
93
CLAUDE.md
93
CLAUDE.md
@@ -267,11 +267,98 @@
|
|||||||
Fixes #123
|
Fixes #123
|
||||||
Types: feat, fix, docs, test, refactor, chore
|
Types: feat, fix, docs, test, refactor, chore
|
||||||
|
|
||||||
|
Test-Driven Development (TDD) - REQUIRED
|
||||||
|
|
||||||
|
**All code must follow TDD principles. This is non-negotiable.**
|
||||||
|
|
||||||
|
TDD Workflow (Red-Green-Refactor)
|
||||||
|
|
||||||
|
1. **RED** — Write a failing test first
|
||||||
|
- Write the test for new functionality BEFORE writing any implementation code
|
||||||
|
- Run the test to verify it fails (proves the test works)
|
||||||
|
- Commit message: `test(#issue): add test for [feature]`
|
||||||
|
|
||||||
|
2. **GREEN** — Write minimal code to make the test pass
|
||||||
|
- Implement only enough code to pass the test
|
||||||
|
- Run tests to verify they pass
|
||||||
|
- Commit message: `feat(#issue): implement [feature]`
|
||||||
|
|
||||||
|
3. **REFACTOR** — Clean up the code while keeping tests green
|
||||||
|
- Improve code quality, remove duplication, enhance readability
|
||||||
|
- Ensure all tests still pass after refactoring
|
||||||
|
- Commit message: `refactor(#issue): improve [component]`
|
||||||
|
|
||||||
Testing Requirements
|
Testing Requirements
|
||||||
|
|
||||||
- Minimum 85% coverage for new code
|
- **Minimum 85% code coverage** for all new code
|
||||||
- Write tests before implementation (TDD)
|
- **Write tests BEFORE implementation** — no exceptions
|
||||||
- All tests must pass before PR merge
|
- Test files must be co-located with source files:
|
||||||
|
- `feature.service.ts` → `feature.service.spec.ts`
|
||||||
|
- `component.tsx` → `component.test.tsx`
|
||||||
|
- All tests must pass before creating a PR
|
||||||
|
- Use descriptive test names: `it("should return user when valid token provided")`
|
||||||
|
- Group related tests with `describe()` blocks
|
||||||
|
- Mock external dependencies (database, APIs, file system)
|
||||||
|
|
||||||
|
Test Types
|
||||||
|
|
||||||
|
- **Unit Tests** — Test individual functions/methods in isolation
|
||||||
|
- **Integration Tests** — Test module interactions (e.g., service + database)
|
||||||
|
- **E2E Tests** — Test complete user workflows with Playwright
|
||||||
|
|
||||||
|
Running Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm test # Run all tests
|
||||||
|
pnpm test:watch # Watch mode for active development
|
||||||
|
pnpm test:coverage # Generate coverage report
|
||||||
|
pnpm test:api # API tests only
|
||||||
|
pnpm test:web # Web tests only
|
||||||
|
pnpm test:e2e # Playwright E2E tests
|
||||||
|
```
|
||||||
|
|
||||||
|
Coverage Verification
|
||||||
|
|
||||||
|
After implementing a feature, verify coverage meets requirements:
|
||||||
|
```bash
|
||||||
|
pnpm test:coverage
|
||||||
|
# Check the coverage report in coverage/index.html
|
||||||
|
# Ensure your files show ≥85% coverage
|
||||||
|
```
|
||||||
|
|
||||||
|
TDD Anti-Patterns to Avoid
|
||||||
|
|
||||||
|
❌ Writing implementation code before tests
|
||||||
|
❌ Writing tests after implementation is complete
|
||||||
|
❌ Skipping tests for "simple" code
|
||||||
|
❌ Testing implementation details instead of behavior
|
||||||
|
❌ Writing tests that don't fail when they should
|
||||||
|
❌ Committing code with failing tests
|
||||||
|
|
||||||
|
Example TDD Session
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. RED - Write failing test
|
||||||
|
# Edit: feature.service.spec.ts
|
||||||
|
# Add test for getUserById()
|
||||||
|
pnpm test:watch # Watch it fail
|
||||||
|
git add feature.service.spec.ts
|
||||||
|
git commit -m "test(#42): add test for getUserById"
|
||||||
|
|
||||||
|
# 2. GREEN - Implement minimal code
|
||||||
|
# Edit: feature.service.ts
|
||||||
|
# Add getUserById() method
|
||||||
|
pnpm test:watch # Watch it pass
|
||||||
|
git add feature.service.ts
|
||||||
|
git commit -m "feat(#42): implement getUserById"
|
||||||
|
|
||||||
|
# 3. REFACTOR - Improve code quality
|
||||||
|
# Edit: feature.service.ts
|
||||||
|
# Extract helper, improve naming
|
||||||
|
pnpm test:watch # Ensure still passing
|
||||||
|
git add feature.service.ts
|
||||||
|
git commit -m "refactor(#42): extract user mapping logic"
|
||||||
|
```
|
||||||
|
|
||||||
Docker Deployment
|
Docker Deployment
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user