What is the testing pyramid in CI/CD and where does each test type run?

Answer

The testing pyramid (by Mike Cohn) recommends having many unit tests at the base, fewer integration tests in the middle, and a small number of end-to-end tests at the top. In a CI/CD pipeline: Unit tests (base) run on every push — fast (seconds), test business logic in isolation, should be thousands of them. Integration tests run after unit tests — test a service with its real database and dependencies (using Testcontainers or a test environment), slower (minutes), catch wiring and SQL bugs. Contract tests (Pact) run in CI — verify service API compatibility without a full environment. End-to-end (E2E) tests run against staging — simulate real user flows in a full deployed environment, slowest (tens of minutes), kept to a minimum covering critical user journeys. The pyramid shape enforces investing most effort where tests are fastest and cheapest to run.