Learning CenterClaude CodeTesting with Claude Code
Intermediate8 min read

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:

  1. Write a failing test (RED)
  2. Run it — confirm it fails
  3. Write minimal implementation (GREEN)
  4. Run it — confirm it passes
  5. Refactor (IMPROVE)
  6. 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:

  1. Write a reproduction test first (RED)
  2. Confirm the test catches the bug
  3. Fix the implementation (GREEN)
  4. 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.

Loading…