Testing and quality · Comparison

Unit vs integration vs end-to-end tests

The three layers of the testing pyramid. Each catches different bugs at a different cost, and a healthy suite has many unit tests, a fair number of integration tests and a few end-to-end tests.

3 options · 8 questions side by side · updated

CompareUnit testsIntegration testsEnd-to-end tests
What it checksOne function or module on its ownSeveral parts working togetherA whole user journey in a browser
SpeedMilliseconds eachFractions of a second to secondsSeconds to minutes each
Setup neededAlmost noneA test database or servicesA running app, browser and test data
Typical toolsVitest, Jest, pytestVitest, Jest, pytest, Testing LibraryPlaywright, Cypress
CatchesLogic and edge-case bugsMismatches between partsBroken journeys users would hit
FlakinessRareOccasionalMost common
How manyManySomeA few, on key journeys
When to runOn every save and every commitOn every pull requestOn pull requests and before a release

How to choose between Unit tests, Integration tests and End-to-end tests

  • Write unit tests for logic with rules and edge cases, such as prices, dates and permissions.
  • Add integration tests where parts meet: API routes with a real database, forms with their validation.
  • Keep end-to-end tests for the journeys that must never break, such as sign-in and checkout.

The options

More comparisons

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.