Layer tests by cost and speed: unit tests for domain logic, integration tests for DB and services, contract tests for HTTP API, and E2E tests for critical user flows using Playwright.
Unit tests: pure functions, domain logic, error handling — fast, no I/O, run on every commit
Integration tests: repository + real DB (testcontainers), service + message queue — run on PR
API contract tests: HTTP handlers with httptest.NewServer + real DB — verify request/response shapes
E2E tests: Playwright/Cypress against a deployed staging environment — run before production deploy
Race detector: go test -race in CI catches data races missed by functional tests