Testing with Claude Code
Use TDD workflows, generate tests automatically, and maintain 80%+ coverage.
The TDD Mandate
Every non-trivial feature should follow Test-Driven Development. Claude Code supports this natively with the /tdd skill and the tdd-guide agent.
The workflow:
- Write a failing test (RED)
- Run it — confirm it fails
- Write minimal implementation (GREEN)
- Run it — confirm it passes
- Refactor (IMPROVE)
- Verify coverage stays above 80%
Asking Claude to Write Tests First
Prompt pattern:
"Before implementing the password reset feature, write a comprehensive test suite covering: successful reset, expired token, already-used token, invalid email. Make all tests fail first."
This forces Claude to think through edge cases before writing implementation code.
Test Stack
The ReadyIQ Platform uses:
- Vitest for unit and integration tests
- Playwright for E2E tests
- jsdom for DOM testing in Vitest
Run tests:
npm run test # Vitest watch mode
npm run test:coverage # Coverage report
npx playwright test # E2E tests
Coverage Floors
80% is the minimum. Ask Claude to check coverage after major changes:
"Run the test suite and check coverage. If any module is below 80%, identify the gaps and write tests to fill them."
Bug Fix Protocol
For every bug fix:
- Write a reproduction test first (RED)
- Confirm the test catches the bug
- Fix the implementation (GREEN)
- Sweep the codebase for sibling bugs using the same pattern
This is the operationalize-fixes workflow — every bug is a class of bugs, not a single instance.