Unit isolates one component, integration tests interactions, end-to-end tests the whole system
The three levels differ in scope and in what they allow to be real. A unit test exercises a single function or class in isolation, with every external dependency replaced by a fake, so a failure points at one piece of logic. An integration test exercises several real components together, such as your repository against a real database, so it catches contract mismatches that unit tests cannot see. An end-to-end test drives the system through its real entry point, typically HTTP or the CLI, against a deployed or fully wired environment, so it validates that the whole thing works from the user's perspective. The test pyramid is the guiding heuristic: many fast unit tests, fewer integration tests, and a small number of slow end-to-end tests. The reason is not dogma but cost: unit tests run in milliseconds and pinpoint failures, while end-to-end tests are slow, flaky, and expensive to debug.
Unit: pure function or class under test, all collaborators mocked or faked, deterministic, fast, no IO.
Integration: real database, real message broker, or real filesystem, but typically not the whole service. Verifies contracts and configuration.
End-to-end: real deployment or a full local stack, real HTTP, real auth. Verifies the user-visible path and deployment wiring.
Trade-off: the more real the environment, the higher the confidence but the slower and more brittle the test. Push verification down the pyramid whenever possible.
Common mistake: writing only unit tests with everything mocked, which passes even when the real database schema does not match.
Common mistake: calling a test an integration test because it starts a server, when it actually mocks the database and the message broker. That is still effectively a unit test with overhead.
Version note: the pyramid is a heuristic, not a standard. Some teams use test trophies or honeycomb models depending on their risk profile.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience