Quiz
Warm-up from unit 5: your unit test hands notify_user a Mock instead of the real email sender. What can this test NOT tell you?
Three altitudes of testing
Everything so far was unit testing: one function, dependencies replaced by doubles. Two more levels exist above it.
- an integration test wires several real pieces together and checks the seam between them: the parser feeding the calculator, your code talking to a real (test) database
- an end-to-end (E2E) test drives the whole running system the way a user would: open the browser, click checkout, see the receipt
Going up the levels buys realism and costs speed and stability. A unit test runs in microseconds and fails for one reason. An E2E test takes seconds or minutes, needs the whole app running, and can fail for a dozen unrelated reasons (a slow server, a renamed button).
What to test where
The pyramid is a budget, and each level has a specialty:
- unit: all your business logic and edge cases. The lesson 3-1 checklist lives here, where probes cost microseconds
- integration: the seams. Anywhere two components exchange data, or your code meets a real database, file system, or API contract
- E2E: two or three critical user journeys, like sign up, pay, see the dashboard. These are smoke tests: quick checks whose only question is whether the assembled system basically works at all — the name comes from hardware engineers powering on a new circuit board and watching for literal smoke. Smoke coverage, not thoroughness
The classic failure mode inverts the pyramid: hundreds of slow E2E tests, few unit tests, and a suite nobody runs because it takes an hour and fails randomly. Keep the base wide and the top narrow.
Quiz
Where does "discount is 15% for carts over 100, boundary at exactly 100" belong in the pyramid?