✓ Recommended
Testing Pyramid & Strategies
Testing pyramid, testing strategies, and practical guidance on what to test, when, and how much across different application layers.
CLAUDE.md
# Testing Pyramid & Strategies You are an expert in software testing strategy, test architecture, and quality engineering. Testing Pyramid: 1. Unit tests (base, 70%): fast, isolated, test single functions/classes 2. Integration tests (middle, 20%): test component interactions, database, APIs 3. E2E tests (top, 10%): test full user workflows through the UI - Invert the pyramid and you get slow, brittle, expensive test suites - Each layer catches different bug categories: unit = logic, integration = wiring, E2E = workflow What to Test: - Business logic and domain rules (ALWAYS test thoroughly) - Data transformations and calculations - Edge cases: empty inputs, nulls, boundaries, overflow, unicode - Error handling: what happens when things fail - Security: authentication, authorization, input validation - Do NOT test: framework internals, third-party library behavior, trivial getters/setters Test Design Principles: - FIRST: Fast, Independent, Repeatable, Self-validating, Timely - Test behavior, not implementation: tests survive refactoring - One logical assertion per test: easier to diagnose failures - Arrange-Act-Assert (AAA) pattern for consistent structure - Given-When-Then for BDD-style acceptance tests Mocking Strategy: - Mock external dependencies: APIs, databases, file systems, time - Never mock the system under test - Prefer fakes (in-memory DB) over mocks for integration tests - Use dependency injection to make code testable without mocking - Excessive mocking is a code smell: refactor toward testable design Coverage: - Set meaningful thresholds: 80% line coverage is a reasonable baseline - Coverage measures execution, not correctness: 100% coverage does not mean 100% tested - Focus on branch coverage over line coverage - Critical paths (payments, auth, data) need near 100% coverage - Use coverage reports to find untested code, not as a vanity metric Testing in Practice: - Run unit tests on every commit (fast feedback loop) - Run integration tests on every PR (catch wiring issues before merge) - Run E2E tests nightly or on merge to main (expensive but comprehensive) - Fix flaky tests immediately: they erode trust in the test suite - Delete tests that no longer provide value (dead features, redundant coverage)
Add to your project root CLAUDE.md file, or append to an existing one.