TL;DR
A testing portfolio that earns its keep: the pyramid economics, contract tests that replace slow E2E suites, and the few end-to-end journeys worth paying for.
Every team eventually faces the same question, usually at 4pm on the day a release is already late: where does the next test go? The suite is slow, the build is red for reasons nobody can reproduce, and someone suggests adding more end-to-end tests — because end-to-end tests look like the user, and that feels like confidence. It is the most expensive way to buy the least confidence, and the shape of a good testing portfolio has been understood for fifteen years. The discipline is not writing more tests. It is deciding which layer earns each test, what coverage number is honest rather than vanity, and how to keep the suite fast and trustworthy as it grows.
The model most teams start from is the test pyramid. Mike Cohn first sketched it in conversation with Lisa Crispin in 2003–2004 and published it in his 2009 book Succeeding with Agile, where he called it the "test automation pyramid". Martin Fowler popularised it as the counterweight to suites dominated by brittle UI tests, and Ham Vocke's 2018 "The Practical Test Pyramid" made it the canonical engineering reference. The shape encodes a cost gradient: tests near the base are fast, cheap, and numerous; tests near the top are slow, brittle, and few. The discipline is keeping the proportions right.
The pyramid, layer by layer
Unit tests — the base. One function or class, in isolation, with its collaborators replaced by fakes. They run in milliseconds, they almost never flake, and when one fails it points at exactly the function and input that broke. They are the only layer that can cover edge cases exhaustively — every branch of a pricing rule, every malformed input to a parser — because each case costs almost nothing to run. What they cannot do is tell you whether the parts work together. A suite of passing unit tests can sit on top of a completely broken system, which is why the base alone is never enough.
Integration tests — the middle. Several parts wired together: a service and its database, a component rendered with its real children, an API and the code behind it. They catch the bugs that live in the seams — the query that works in isolation but deadlocks under the real transaction, the serialiser that drops a field the consumer needs. They are slower than unit tests and their failures point at a component rather than a line, but they are still fast enough to run on every pull request. In a front-end application this layer is where most of the value sits, which is why Kent C. Dodds's testing trophy (2018) — building on Guillermo Rauch's advice, "Write tests. Not too many. Mostly integration." — makes integration the widest band and adds static analysis (type checking, linting) as a base layer beneath unit tests. The pyramid and the trophy disagree about proportions, not about principle: both say the expensive top layer should be small.
End-to-end tests — the tip. The whole deployed system, driven the way a user drives it, usually through a real browser. They are the only layer that verifies the wiring between frontend, backend, and database, and they are the slowest, most expensive, and most likely to flake. A change to a button label, a slow third-party script, a timing race in an animation — any of them can turn a green build red for reasons that have nothing to do with the product. Fowler's summary is blunt: tests that run end-to-end through the UI are brittle, expensive to write, and time-consuming to run. So the pyramid argues for a few of them, covering the journeys that would cost the business if they broke, and nothing else.
The numbers: 70/20/10 is a first guess, not a quota
The split most often quoted is 70% unit, 20% integration, 10% end-to-end. It comes from the Google Testing Blog's 2015 post "Just Say No to More End-to-End Tests" by Mike Wacker, which offered it explicitly as "a good first guess" and added that the exact mix will be different for each team. Cohn himself never put ratios in print. Treat the numbers as a prompt to question a suite dominated by expensive broad checks, not as a target to hit regardless of architecture or risk: a front-end-heavy product will legitimately run fatter on integration tests (the trophy shape), a library of pure functions will legitimately run fatter on unit tests, and a system of many small services will need the layer the pyramid leaves out — contract tests.
The honest way to use the pyramid is as a diagnostic. Count your tests by layer. If unit tests are not the majority by count, something is wrong — unless you can name the architectural reason (a thin UI over a third-party API, a service that is mostly orchestration). If your end-to-end suite takes longer than your pull-request patience, the fix is not a faster runner. It is moving coverage down a layer.
The missing layer: contract tests
The pyramid's blind spot is the boundary between services owned by different teams. An integration test that starts both services together is slow, couples two teams' release trains, and breaks whenever either side changes its test data. A unit test with a mocked HTTP client proves nothing about the real provider — the mock will happily agree with whatever the consumer assumed, including assumptions the provider stopped satisfying three releases ago.
Contract testing closes that gap, and the tool that defines it is Pact. Pact was written in 2013 by a team at realestate.com.au (including Ron Holshausen of DiUS) that was trying to integration-test a new Ruby microservices architecture; Beth Skurrie, who had seen J.B. Rainsberger's talk "Integration tests are a scam", pushed the team toward consumer-driven contracts, and provider states — the ability to run the same request under different conditions — were born from that collaboration. The idea is simple and it inverts the usual direction: the consumer writes the contract. The consumer's test runs against a Pact mock provider, records the exact requests it makes and the responses it depends on, and publishes that contract to a broker. The provider then replays every recorded request against its real implementation and proves it still returns what the consumer needs — before either side ships. Neither service ever has to run at the same time as the other.
A short consumer test shows the shape. This is Pact's JavaScript form, and the same structure exists in every language Pact supports:
import { PactV3, MatchersV3 } from '@pact-foundation/pact';
// The consumer states what it needs: given a user exists,
// GET /users/123 returns that user with an id and a name.
const provider = new PactV3({ consumer: 'web-bff', provider: 'user-service' });
await provider
.given('user 123 exists')
.uponReceiving('a request for user 123')
.withRequest({ method: 'GET', path: '/users/123' })
.willRespondWith({
status: 200,
body: { id: MatchersV3.like(123), name: MatchersV3.like('Kavi') },
})
.executeTest(async (mock) => {
const user = await getUser(mock.url, 123);
expect(user.name).toBe('Kavi');
});
// The test writes a contract file; the provider verifies it in its own pipeline.Two details in that sketch carry the whole technique. First, the matchers (like) say the consumer cares about the shape — an id that is a number, a name that is a string — not the literal values, so the provider is free to change its test data. Second, the contract is generated by the consumer's own tests, which means it can only ever describe behaviour the consumer actually uses. A provider that adds a field breaks nothing; a provider that removes a field the consumer reads fails the provider's build before the change ships. That is the property integration tests cannot give you: a breaking change caught by the team that made it, in their own pipeline.
Spring teams have a parallel option in Spring Cloud Contract, where the contract is written as a Groovy DSL and kept with the producer (or in an external repository) rather than generated by the consumer's tests. Pact is the natural fit when the consumer should drive the contract across languages; Spring Cloud Contract is the natural fit for a JVM-and-Spring estate that wants contracts as checked-in specifications. Either way, the decision is the same: if two services are owned by different teams and change on different schedules, the boundary between them needs a contract test, and the end-to-end tests that used to cover that boundary can be deleted.
The options head-to-head
| Layer | Speed | What it catches | What it cannot catch | When it fails you |
|---|---|---|---|---|
| Static (types, lint) | Instant, in the editor | Typos, wrong types, unused code | Any runtime behaviour | It cannot run the code |
| Unit | Milliseconds | Wrong results from one function | Seams between parts | Mocks drift from reality |
| Integration | Seconds | Wiring between components, real queries | Cross-team boundaries | Needs real services or faithful fakes |
| Contract | Seconds, per side | Breaking API changes, before either side ships | Behaviour inside either service | Only covers what the consumer uses |
| End-to-end | Minutes | The whole system, as the user sees it | Nothing cheaply — every failure is expensive to diagnose | Flakes, slow builds, eroded trust |
| Manual / exploratory | Human time | The things no one thought to automate | Everything, repeatedly | Does not scale, does not regress |
Read the table as a cost curve, not a ranking. Each layer trades cost for confidence in the opposite direction, and the portfolio is balanced when the cheap layers catch the cheap bugs and the expensive layer is reserved for the failures only it can see.
Where end-to-end earns its keep
End-to-end tests are not the enemy; the enemy is end-to-end tests doing a job a cheaper layer could do. The journeys worth paying for are the ones where failure costs the business directly and no lower layer can see the failure at all:
Everything else — edge cases, error states, form validation, permission matrices — belongs lower. A good rule, from the Google post, is that each time a bug is uncovered by an end-to-end test, a unit test should be added to identify and permanently prevent it. The E2E test found the hole; the unit test owns it from then on.
Keep the E2E suite honest with a flakiness budget. A test that fails without a product change is not a test, it is a random number generator with a red badge, and every flaky failure trains the team to ignore red builds. Quarantine a flaky test — move it out of the blocking suite, file it with the failure evidence, fix or delete it on a deadline — instead of retrying it blindly until it passes. Retries do not fix flakiness; they hide it until the day the retry budget runs out during a real incident. Our CI/CD pipelines guide covers where each tier runs: unit and contract tests on every pull request, integration tests in parallel jobs with service containers, the critical-path E2E journeys on pull requests, and the full E2E suite on a schedule or before deployment.
A minimal Playwright check for a critical journey shows how little an E2E test needs to contain. It asserts the outcome a user cares about, not the implementation:
import { test, expect } from '@playwright/test';
// Critical journey only: a user can sign up and reach their dashboard.
test('signup completes and lands on the dashboard', async ({ page }) => {
await page.goto('/signup');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('correct-horse-battery-staple');
await page.getByRole('button', { name: 'Create account' }).click();
await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
});If that test needs twenty more like it to feel safe, the safety is missing lower down. Add the coverage where it is cheap, not where it is visible.
The failure shapes
When the proportions invert, the suite tells you in its own language. The ice-cream cone — named by Alister Scott in January 2012, and described by Fowler as the shape a record-and-playback UI suite grows into — is a pyramid upside down: most checks are manual tests and tests through the user interface, few are unit tests. It feels productive early (the UI tests "prove" the app works), then collapses under its own weight: every change triggers a long, flaky run, and engineers stop trusting red builds. The hourglass is the subtler cousin: many unit tests and many E2E tests, almost nothing in the middle, because developers write unit tests and QA writes E2E tests and nobody owns the integration layer. The symptom is a suite that is green at both ends and still ships broken seams. Both shapes are fixed the same way — not by deleting E2E tests, but by writing the missing lower-layer tests that cover the same ground faster.
Recommendation
Default to the pyramid with a contract layer: static checks, a wide unit base, integration in the middle, contract tests on every cross-team boundary, and a small E2E cap on critical journeys. That is the portfolio that survives contact with a real codebase: fast enough to run on every pull request, precise enough that a failure points at the cause, and honest enough that a red build means something.
Adopt contract tests the moment two teams own the two sides of an API. The trigger is not the number of services — it is the number of independent release trains. One team owning both sides can coordinate a breaking change in a single commit; two teams cannot, and the contract is the coordination mechanism that does not require a meeting.
Cap E2E at the journeys you can name on one hand. Signup, login, checkout, payment, and the post-deploy smoke test. If the list needs two hands, the extra journeys are edge cases that belong in a lower layer, and the suite is already drifting toward the cone.
Architecture Decision
>
Decision: Adopt the five-layer portfolio — static checks, unit, integration, consumer-driven contract tests (Pact, or Spring Cloud Contract on JVM estates), and a capped E2E suite on critical journeys only — with a 70/20/10 split as a starting guess and a flakiness budget that quarantines unreliable tests.
>
Context: The suite is slow, E2E-heavy, and flaky; releases are delayed by red builds nobody trusts, and cross-team API changes break consumers after deployment. The product is a set of services owned by several teams, with a web frontend and a small number of revenue-critical user journeys.
>
Options considered: (a) The classic three-layer pyramid (unit, integration, E2E) with no contract layer. (b) The five-layer portfolio with contract tests. (c) The testing trophy (static, unit, integration-heavy, thin E2E) for the frontend. (d) E2E-heavy coverage of every user flow. (e) No fixed portfolio — each team chooses its own mix.
>
Why this one: Option (b) is the only one that covers the cross-team boundary, which is where this system's failures actually come from — the pyramid alone (a) leaves that boundary to slow integration tests or to E2E. Option (c) is adopted for the frontend, where integration tests give the most confidence per test; the trophy and the pyramid are the same economics with different proportions. Option (d) is the ice-cream cone: it maximises the slowest, flakiest layer and trains the team to ignore red builds. Option (e) produces an hourglass — every team optimises its own layer and nobody owns the seams.
>
What it costs you: Contract tests need a broker and a discipline — consumers must publish contracts, providers must verify them in their own pipeline, and a contract that nobody maintains rots into a false green. The E2E cap means some flows are covered only by lower layers, so a purely visual regression can slip through; that is what visual regression testing is for, not more E2E. The flakiness budget costs a weekly slot to fix or delete quarantined tests.
>
When to reverse it: If the services consolidate under one team and one release train, drop the contract layer — the boundary it guards no longer exists. If the product becomes a single-page app with almost no backend of its own, shift the weight toward the trophy shape. If the system gains non-deterministic components (LLM features, recommendations), the pyramid does not cover them — those need evaluation harnesses with golden datasets and human review, which are a different discipline from tests with deterministic expectations.
When not to use the pyramid
Do not apply the pyramid to a system it was not drawn for. Spotify's testing honeycomb, written for microservices, puts most effort into tests that exercise a whole service through its real interfaces, with very few tests of internal details — the right shape when each service is small and its boundary is the product. Do not apply it to non-deterministic systems: an LLM feature cannot be unit-tested into correctness, because the same input legitimately produces different outputs; that needs evals, not assertions. And do not apply it to a throwaway script: a migration run once, a demo built for a day, a prototype that will be deleted on Friday — the cheapest test for those is running them once and watching. The pyramid is a portfolio strategy for software that will be changed by more than one person for more than one quarter. Outside that, it is ceremony.
Conclusion
A testing strategy is a budget, and the pyramid is the budget's shape: spend most of it where tests are fast and precise, some of it where parts meet, and a small, deliberate amount where only the whole system can tell you the truth. Add the layer the original pyramid left out — contract tests on every boundary between teams — and cap the expensive top at the journeys that would cost the business if they broke. Measure the portfolio by counting tests per layer and by timing the pull-request build, not by a coverage percentage, and quarantine anything flaky before it teaches the team to ignore red. The suite that earns its keep is the one developers trust enough to run, and fast enough that they actually do.
For the surrounding decisions, our CI/CD pipelines guide covers where each test tier runs in the pipeline, our DevOps metrics guide covers measuring the suite and the delivery it guards, and our SLOs and error budgets guide covers the reliability targets the tests exist to protect. Our GitOps guide covers the deployment gates the E2E smoke tests run behind, and our modular monolith vs microservices guide covers the prior decision — how many services, and therefore how many contract boundaries, the system should have at all.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.