Back to results for “UI Testing”
Angular › End to End Testing with Cypress & Playwright

Why should a team combine end to end tests with unit tests rather than relying on just one type?

Beginner

Answer

Unit tests are fast and pinpoint exactly which small piece of code broke, but cannot catch problems that only appear when pieces are combined together, like a broken navigation flow. End to end tests catch these bigger, real world problems but run slower and are less precise about exactly what broke. Using both together gives a team confidence at every level.
// Unit test, fast, checks one small piece in isolation
it('formats price correctly', () => {
  expect(formatPrice(9.5)).toBe('$9.50');
});

// End to end test, slower, checks the whole real user flow
cy.visit('/checkout');
cy.contains('$9.50').should('be.visible');
Real-world example A team relies on a large number of fast unit tests for detailed logic checks, combined with a smaller number of end to end tests covering their most critical user flows, like checkout and login, catching different kinds of problems at each level.

Common follow-ups: What is a reasonable ratio of unit tests to end to end tests for a typical project?;Which type of test should a team prioritize writing first when starting a new project?