CC-301h · Module 3
Test Organization Patterns
3 min read
Test files accumulate faster than source files. A codebase with 200 source files might have 400 test files — unit tests, integration tests, e2e tests, snapshot tests, each in different directories with different conventions. Claude Code navigates this complexity better when you document the testing structure in CLAUDE.md.
The test structure rule belongs in your architecture section: "Unit tests: co-located with source files (Button.test.tsx next to Button.tsx). Integration tests: in tests/integration/, one file per user flow. E2e tests: in tests/e2e/, organized by page. Test utilities: in tests/helpers/." Claude uses this map to put new tests in the right place and to find existing tests when debugging failures.
## Test Structure
- Unit tests: co-located with source (`*.test.ts` next to `*.ts`)
- Integration tests: `tests/integration/` (one file per user flow)
- E2e tests: `tests/e2e/` (organized by page/feature)
- Test helpers: `tests/helpers/` (shared mocks, factories, utilities)
- Naming: `describe` block matches file name, `it` blocks read as sentences
- Mocking: prefer dependency injection over module mocking when possible