System Design · 08. Shipping · 8 min · Beginner

Testing

Find the bug before your users do, without waiting all day.

In short

Our suite has 1,150 tests and runs in about 5.6 min: unit tests for the details, integration tests for the joins, a few E2E journeys, and contract tests between services.

Load tests find the limit; chaos tests check the system survives failures. Keep the pyramid the right way up, and keep every test fast and trustworthy.

Key ideas

  • The later a bug is found, the more it costs: a customer's money, a support call, a night fix. (step 1)
  • Test each thing at the lowest level that can catch it. Use the slow tests only for what the fast ones cannot see. (step 5)
  • Load tests answer "how many users can we take?", the capacity question from napkin math, with measurements instead of guesses. (step 7)

Good to know

  • Fast tests get run all the time, on every save. Slow tests get skipped. (step 2)
  • The contract is a shared promise. Breaking it fails the provider's build, before anyone deploys. (step 6)

Watch out

  • Give every test fresh data and clean up after it. Tests that share data fail in confusing ways. (step 3)
  • A flaky test teaches people to ignore red. Fix it or delete it. (step 4)
  • Begin in a test environment or with a tiny share of traffic. Chaos is an experiment, not a surprise. (step 8)
Unit: 1,000Integration: 100End-to-end: 20

Key numbers

Tests
1,150
Run time
5.6 min
Failure points to
a small area

Terms

Unit test
A test of one small function with no network or database; fast and exact.
Integration test
A test that runs real parts together, such as the app and a test database.
End-to-end test
A test that drives a real browser through the whole system like a user.
Flaky test
A test that sometimes fails when nothing is broken.
Test pyramid
Many fast unit tests, fewer integration tests, and very few end-to-end tests.
Contract test
A check that a service still keeps the API another service expects.
Load test
Sending many fake users to find how much traffic the system can take.
Chaos testing
Causing failures on purpose, carefully, to check the system survives them.