Foundations · L1Testing strategy that scales

Testing strategy that scales

Which tests to write at each level, how to keep a growing suite fast and trusted, and how to spot tests that check nothing.

L1 Must-knowFoundations18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

A team runs an online shop. Its main test suite clicks through the site in a real browser: sign in, search, add to cart, pay. There are 300 of these tests, and the suite takes 40 minutes.

Every week a few tests fail with no change to the code. A timeout here, a slow page there. The team learns a habit: when a test fails, press "re-run". Usually it turns green.

One Friday, the payment test fails. A developer re-runs it twice, and on the third run it passes. He merges. The failure was real: a race in the new payment code that showed up only some of the time. Customers were charged twice over the weekend.

This story is made up. But Google has seen the same thing: developers dismiss a failure as flaky and later find it was a real bug. 4 The tests were not the problem. The strategy was.

Section 2 of 8

The idea in simple words

Tests are not there to find bugs once. They are there so you can change code with confidence, again and again, for years. 1 A good suite tells you fast, and truthfully, if your change broke something.

Tests come in three common scopes:

Lower tests are fast and cheap, and a failure points close to the cause. 1 Tests through the UI are slow, brittle and expensive to write, but they see the real system. 5 A strategy is the mix you choose, and the rules that keep it fast and trusted.

The key idea. Write many small, fast tests and only a few large ones. In our view, a test that people do not trust does harm, because it teaches them to ignore red.

Section 3 of 8

How it works

Step through one change as it passes four layers of checks. Use Next and Back, or the ← and → keys.

One change, four checks: what unit, integration, end-to-end and canary each catchChange: new discount Unitsmall · limit 60 s Integrationmedium · limit 300 s End-to-endlarge · 900+ s Canaryreal users (example) caught: 10% off ₹999rounds to ₹899.09 caught: SQL uses acolumn that is not there caught: checkout pagehides the discount caught: slow query onreal data · rolled back earlier = faster and cheaper to fix✓ Each layer catches what the one before cannot SeniorPath
  1. In this example, a developer changes how discounts work. Unit tests run first, on her laptop and in CI. Here they are also what Google calls small tests: one process, no network, a 60-second limit. One catches a rounding bug.
  2. Integration tests run the code with a real database on the same machine. In Google's terms these are medium tests, with a 300-second limit. A unit test with a fake database could not see that the SQL names a column that does not exist.
  3. A few end-to-end tests click through checkout in a real browser, against the whole system. They are slow and can be flaky, so you keep them few. One finds that the page does not show the discount.
  4. After the merge, the change goes to a canary: a small share of servers with real users. Canary analysis compares its health with the rest of production. A query that was fast on test data is slow on real data. Latency goes up on the canary, so the rollout stops and rolls back.
  5. The bugs here are examples. Higher layers are slower and cost more, but they see more of the real system. Push each check as low as it can go, and keep the top layers small.
Step 1 of 5

The test pyramid. Mike Cohn made the pyramid popular in his 2009 book Succeeding with Agile. The bottom is many unit tests. The top is a few tests through the UI. 5 Ham Vocke sums it up in two rules: write tests at different levels, and the higher the level, the fewer tests you should have. 6 As a very rough guide, Google aims for about 80% unit, 15% integration and 5% end-to-end tests. 1

The opposite shape is the ice cream cone: many end-to-end tests and few unit tests. Google says such suites tend to be slow, unreliable and hard to work with. 1 The team in the story had an ice cream cone.

The critics: the testing trophy. Kent C. Dodds draws a trophy instead. From the bottom, it has static checks, unit tests, integration tests and end-to-end tests. He builds on Guillermo Rauch's advice: "Write tests. Not too many. Mostly integration." His rule: "The more your tests resemble the way your software is used, the more confidence they can give you." 7 He made it for JavaScript apps, mostly in one codebase. 7 In our view, both shapes agree on the main point: keep end-to-end tests few. They differ on how much weight integration tests get.

Size is not the same as scope. "Unit" and "integration" mean different things to different teams. So Google also sorts tests by the resources they use. 3

  • Small: one process, no network, no disk, no sleep. Time limit 60 seconds.
  • Medium: one machine. Network to localhost only, so a database in a container is fine. Limit 300 seconds.
  • Large: anything, across many machines. Limit 900 seconds or more. 3 1

Google cares most about speed and determinism, and size predicts both. 1 A test that cannot touch the network cannot fail because the network was slow.

Flaky tests. A flaky test passes and fails on the same code. In 2016, Google reported that about 1.5% of all its test runs gave a flaky result. Almost 16% of its tests had some flakiness. 4 In post-submit CI, about 84% of pass-to-fail changes involved a flaky test. 4 The book says tests begin to lose value as flakiness nears 1%. 1

The real cost is trust. People ignore alarms that are often false, so real failures get dismissed. 4 Google's tools re-run failing tests and quarantine very flaky ones. Quarantine has a cost: it can hide a real race in the code. 4 Treat a flaky test as a bug with an owner, not as noise.

Test data. Large tests need data that looks real. Data written by hand covers a narrow range of cases and reflects the author's biases. Copied production data is more real, and a sample of it keeps the size down. 2 Google's book says tests should not depend on the order they run in, or on a shared database. 1 So let each test create its own data.

Contract tests between services. End-to-end tests across many services are slow and brittle. A contract test checks each service alone against a shared contract. 8 In Pact, the consumer's tests generate the contract, so it holds only the requests the consumer really uses. The provider then checks that it can answer them. 8 6

Testing in production. Some bugs appear only with real traffic, real data and real config. Google's book says config changes are the number one cause of its major outages. Unit tests alone cannot check them. 2 So the last check runs in production. A prober is a test that checks production, usually with read-only actions. During a staged rollout, canary analysis compares the canary's health with the rest of the fleet. 2 See Safe deploys and config changes for how a canary stops a bad release.

Mutation testing. Line coverage only shows which code ran during tests. It does not show that a test would notice a bug. Mutation testing makes small changes to your code, such as flipping a condition, and runs the tests again. If a test fails, the change is "killed". If all tests still pass, the change "lived", and your tests missed it. 9 It runs your tests many times, once per change. So we suggest you start with the code that matters most. See Property-based and mutation testing.

What to test first. You cannot test everything, so start with risk. Ask: what costs the most if it breaks, and what changes most often? Money, auth, data loss and shared libraries come first. Google calls this the Beyoncé Rule: test everything you do not want to break. In its words, "If you liked it, then you shoulda put a test on it." 1

Section 4 of 8

Trade-offs

OptionSpeedWhat it catchesWhat it missesKeep it
Unit (small)Fast. Run them on every change.Logic, edge cases, rounding. Points close to the cause.Wrong SQL, config, how parts fit together.Many. Most of the suite. 1
Integration (medium)Slower. Limit 300 s per test. 3Real database, queues, serialisation.Other teams' services, the full user flow.A good number, for each boundary you own.
ContractEach side runs alone, without the full system. 8Broken requests or responses between services.Whether the whole flow works for a user.One per consumer and provider pair.
End-to-end (large)Slow. Often flaky. 6A broken user journey across the system.Exact cause of a failure.Few. Only key journeys, like sign-up and pay.
Canary in productionSlow. It waits for real traffic.Real data, real load, real config. 2Bugs that hit only rare users. Some users see errors.On every deploy.

Simple rule: test each thing at the lowest level that can catch it. When a higher test finds a bug, add a lower test for it. 6

Section 5 of 8

At work: how a senior uses this

  • Ask in design reviews: "How will we know this works, and how fast?" Plan the tests with the feature.
  • Watch suite time. Ask: "How long from push to green?" If it grows, move tests down the pyramid.
  • Track flaky tests on a list with owners. Fix or delete them. Do not let "re-run" become a habit.
  • Use a real database in a container for data code. Use a test double for slow or paid services, like a payment provider.
  • When a bug reaches production, write the lowest test that would have caught it, before you fix it.
  • In reviews, read the assertions first. Ask: "If I broke this code, would this test fail?"
Section 6 of 8

With AI

What to ask the agent

"Write unit tests for applyDiscount. Cover zero, negative, rounding and the maximum value. Every test must assert the exact result."

"Here is our test suite. Which tests are end-to-end checks of logic that a unit test could cover? List them with a lower-level replacement."

"This test is flaky. Read it and list every source of non-determinism: time, order, randomness, network and shared state."

What to check yourself

  • Every test has an assertion that would fail if the code were wrong. AI tools sometimes write tests that only call the code, or assert that a mock was called. See Reviewing human and AI code.
  • The test does not copy the code's logic into the expected value. Then a wrong formula passes.
  • Break the code on purpose, or run a mutation tool. If the tests stay green, they test nothing.
  • No sleep calls, real clocks or real network in unit tests.
  • The agent did not change or delete a failing test to make the build green.
Section 7 of 8

Check yourself

1. Your end-to-end suite takes 40 minutes and fails randomly. Most bugs it finds are logic bugs in one function. What should you do?

Show answer

Write unit tests for those cases, and delete end-to-end tests that only repeat them. Vocke advises pushing tests as far down the pyramid as you can. He deletes high-level tests that lower ones already cover, if they add no extra value.

2. In Google's terms, a test starts a database on the same machine and talks to it on localhost. What size is it?

Show answer

Medium In Google's terms, small tests run in one process with no network. Medium tests stay on one machine and may use localhost. Large tests may span many machines.

3. Why is a test that fails 1 time in 100 so costly?

Show answer

People learn to ignore red builds, so they also ignore real failures. Google saw developers dismiss real failures as flaky, and its book says tests lose value as flakiness nears 1%.

4. An AI writes 20 tests for a function. Coverage is 100%, but none of the tests has an assertion. What tool shows the problem best?

Show answer

Mutation testing, because changed code still passes every test. Coverage only shows which lines ran. Mutation testing changes the code, and if no test fails, the tests check nothing.

5. Two teams own an orders service and a mobile backend that calls it. They want to know if a change breaks the caller, without starting both systems. What fits?

Show answer

A contract test A contract test checks each side alone against a shared contract. In Pact, the consumer's tests generate that contract.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 9 sources and related lessons
  1. Adam Bender, “Testing Overview”, chapter 11 of Software Engineering at Google (O'Reilly, 2020) (opens in a new tab)
    Why we test, test size against test scope, the 80/15/5 mix, the ice cream cone, and the cost of flaky tests.
  2. Joseph Graves, “Larger Testing”, chapter 14 of Software Engineering at Google (O'Reilly, 2020) (opens in a new tab)
    What unit tests cannot see, test data, probers and canary analysis in production.
  3. Simon Stewart, “Test Sizes”, Google Testing Blog, 2010 (opens in a new tab)
    A table of what small, medium and large tests may do, with time limits.
  4. John Micco, “Flaky Tests at Google and How We Mitigate Them”, Google Testing Blog, 2016 (opens in a new tab)
    How often tests flake at Google, why it costs so much, and re-runs and quarantine.
  5. Martin Fowler, “TestPyramid”, martinfowler.com, 2012 (opens in a new tab)
    Where the test pyramid comes from, and why tests through the UI are slow and brittle.
  6. Ham Vocke, “The Practical Test Pyramid”, martinfowler.com, 2018 (opens in a new tab)
    The two rules of the pyramid, consumer-driven contract tests with Pact, and why end-to-end tests should be few.
  7. Kent C. Dodds, “The Testing Trophy and Testing Classifications”, 2021 (opens in a new tab)
    The testing trophy, and the idea that tests should resemble how the software is used.
  8. Pact documentation, “Introduction” (opens in a new tab)
    What contract testing is, and how a contract is generated from the consumer's tests.
  9. PIT mutation testing for Java, pitest.org (opens in a new tab)
    A short, clear explanation of mutation testing and why line coverage is not enough.

Related: Flaky tests and test reliability (coming soon) · Contract and integration tests for services (coming soon) · Property-based and mutation testing (coming soon) · CI/CD and trunk-based development · Safe deploys and config changes · Reviewing code written by humans and AI

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper