Software engineering / Integration vs end-to-end testing

Integration vs end-to-end testing

Unit tests check parts one at a time. Follow an online order to see what tests of several parts together, and of the whole system, add, and what they cost.

Beginner7 steps~6 min
Integration test — checks a few real parts joined together
End-to-end test — drives the whole system like a user
Real part — a piece of the shop, really running
Stand-in — a simple replacement for a real part
// THE SHORT VERSION

In 30 seconds

Parts that each work alone can still fail together. An integration test runs a few real parts joined up, such as your code with a real database, and checks the join.

An end-to-end test runs the whole system and drives it like a user: open the page, click, read the result.

The wider the test, the more it proves, but the slower it is and the more often it fails for no good reason (a flaky test). So teams write many small tests and only a few end-to-end ones, for the journeys that matter most.

Integration vs end-to-end testing, step by step

STEPS01 / 07

The times and test counts are illustrative, and teams draw the line between the levels differently. The 0.99 to the power 20 sum assumes the tests fail independently of each other.

STEP 01 / 07 Units pass, product breaks
THE MATH
each unit: pass together: wrong charge
  1. Step 1: Units pass, product breaks. Two parts of a shop each pass their own unit tests. One returns the total in dollars, the other expects cents, so a 110.00 order is charged as 1.10. Unit tests cannot see this: the mistake sits in the join between the parts.
  2. Step 2: Integration test. An integration test runs a few real parts wired together and checks the join. Here the order service talks to a real database filled with test data. The payment provider, which the team does not control, is replaced by a stand-in.
  3. Step 3: End-to-end test. An end-to-end (E2E) test starts the whole system and drives it from the outside, the way a customer would: a script opens a real browser, clicks Buy and checks that the page says the order went through. Every part and every join is exercised.
  4. Step 4: Realism costs time. The more of the real system a test runs, the more it proves, and the longer it takes. A unit test finishes in milliseconds, an integration test needs a database to start, and an end-to-end test waits for browsers and servers. Slow tests are run less often.
  5. Step 5: Flaky tests. A flaky test sometimes fails although nothing is broken: a page was slow to load, a network reply came late, another test left data behind. More moving parts mean more flakiness, so end-to-end tests suffer most. Once red can mean nothing, people stop trusting the tests.
  6. Step 6: The test pyramid. A common way to balance the three levels is the test pyramid: a broad base of fast unit tests, a smaller layer of integration tests for the joins, and a thin top of end-to-end tests for the journeys that matter most.
  7. Step 7: When to use which. Use an integration test when the question is whether your code works with the real thing next to it: a database, another service, a file format. Keep end-to-end tests for a handful of journeys a user must always be able to finish.
VALUES SO FAR
join bugdollars ≠ centsmissed
integ.····scope
E2E····scope
unit····time
integ.····time
E2E····time
0.99^20····flaky
mix····pyramid

Spotted a mistake on this page?