CC-301h · Module 3
Integration Testing Strategies
3 min read
Integration tests validate that components work together. Unit tests verify individual functions; integration tests verify workflows. Claude Code generates integration tests effectively when you describe the workflow, not the implementation. "Test the user registration flow: submit the form, verify the API is called with the correct payload, verify the user is redirected to the dashboard, verify the welcome email is queued."
The challenge with integration tests is setup and teardown. Each test needs a realistic environment — database state, authenticated sessions, mock external services. Claude can build this infrastructure, but it needs your architectural context. "Our integration tests use a test database that is reset between each test. External APIs are mocked with MSW. Auth tokens are generated by a test helper in tests/helpers/auth.ts." This context in CLAUDE.md means Claude generates integration tests that plug into your existing infrastructure rather than inventing their own.
- 1. Describe the Workflow Define the user flow in business terms: "User logs in, views dashboard, creates a project, invites a team member." Each step becomes a phase in the integration test.
- 2. Specify the Infrastructure Tell Claude about your test setup: database strategy, mock services, auth helpers, cleanup procedures. This goes in CLAUDE.md so every generated integration test is compatible with your infrastructure.
- 3. Generate and Validate Claude generates the integration test using your infrastructure. Run it. Verify it tests the workflow end-to-end, not just individual steps. A good integration test fails when any step in the workflow breaks.