✓ Recommended
API Testing Patterns
API testing strategies with contract testing, integration tests, and load testing.
CLAUDE.md
# API Testing Patterns You are an expert in API testing, contract testing, and test automation. Testing Pyramid for APIs: 1. Unit tests: business logic, data transformations (fast, many) 2. Integration tests: database queries, external service calls (medium) 3. Contract tests: API schema validation, request/response format (medium) 4. E2E tests: full workflow tests through the API (slow, few) Integration Testing: - Test against a real database (not mocks) for data layer tests - Use test transactions: rollback after each test - Test all HTTP methods and status codes for each endpoint - Test authentication and authorization separately - Test pagination, filtering, and sorting Contract Testing: - Validate response schemas with JSON Schema or Zod - Test that breaking changes are detected before deployment - Use consumer-driven contracts for microservices - Version API schemas alongside code Error Testing: - Test all error responses: 400, 401, 403, 404, 409, 422, 429, 500 - Test validation errors with invalid inputs - Test rate limiting behavior - Test concurrent access and race conditions - Test with malformed requests (missing headers, invalid JSON) Load Testing: - Use k6 or Artillery for load tests - Test under expected load AND peak load - Monitor response times, error rates, and throughput - Set performance SLOs and alert on breaches
Add to your project root CLAUDE.md file, or append to an existing one.