What is the testing pyramid?
BeginnerConceptTesting in DevOps
Answer
In one line: The testing pyramid is a guideline for balancing automated tests: many fast unit tests at the bottom, fewer integration tests in the middle, and only a small number of slow end-to-end tests at the top.
/\ End-to-end (UI) tests — few, slow, expensive
/ \
/----\ Integration / API tests — some
/ \
/--------\ Unit tests — many, fast, cheap
The layers:
- Unit tests — test one function or class in isolation, with dependencies mocked. Run in milliseconds. Example:
calculateTax(100)returns18. - Integration tests — test how parts work together: the app with a real database, or two services through an API. Seconds to minutes.
- End-to-end (E2E) tests — test full user journeys through the real UI and all services. Example: open the site, add to cart, pay. Minutes; more fragile.
Why a pyramid shape:
- Unit tests are fast and pinpoint the exact broken code — great for CI on every commit.
- E2E tests catch real-world problems but are slow, flaky and hard to debug when they fail.
- Too many E2E tests and too few unit tests gives the "ice cream cone" anti-pattern: slow pipelines and unreliable results.
How it maps to the pipeline:
- On every PR: unit tests + some integration tests.
- After deploy to test/staging: integration and a focused set of E2E/smoke tests.
- Nightly: full E2E, performance and security suites.
Other layers often added: static analysis at the very bottom, contract tests between services, and manual exploratory testing at the top.
Example: a service has 1,200 unit tests (40 seconds), 150 API integration tests with a Testcontainers database (4 minutes) and 15 critical-path E2E tests with Playwright (6 minutes).
Tip for interviews: explain why the shape matters — speed, cost and reliability of feedback.
More on Testing in DevOps
What is the difference between unit, integration and end-to-end tests?BeginnerWhat are smoke tests and sanity tests?BeginnerWhat is regression testing?BeginnerWhat is test automation, and what should (and shouldn't) be automated?BeginnerWhat is shift-left testing, and how do you apply it in a pipeline?IntermediateWhat is contract testing, and why is it useful for microservices?Intermediate