# What End-to-End Tests Are For — Playwright & Cypress

Source: https://www.skillbyai.com/en/e2e-testing/f-purpose

> Few, valuable, user-level checks.

## The top of the pyramid

An **end-to-end (E2E) test** opens a real browser, loads the running application and acts like a user: it clicks, types and checks what appears on screen, usually with a real or realistic backend behind it. The classic **test pyramid** puts many fast unit tests at the bottom, fewer integration tests in the middle and a small number of E2E tests on top; the **testing trophy** variant puts more weight on integration tests. Either way, E2E tests are the slowest and most expensive to maintain, so they should cover the **critical user journeys** (sign-up, login, checkout, the core workflow of the product) rather than every edge case. Validation rules and calculations are better tested lower down.

## Test the app the way users use it

End-to-end tests drive a real browser against a running application to prove that key user journeys work.

![Three ideas: what E2E tests are for, how Playwright and Cypress are built, setting up each tool.](assets/figures/e2e-testing/section-1-map.svg) — Figure 1.1 — Where E2E tests sit, and how the two tools talk to the browser.

## Deciding what deserves an E2E test

A rough triage list.

```bash
# good E2E candidates (high value, crosses many layers)
#   - a new user can sign up and reach the dashboard
#   - a signed-in user can add an item to the cart and pay
#   - an admin can invite a teammate and the invite email is queued
#
# better tested lower in the stack
#   - every validation message on a form     -> component / unit tests
#   - price calculation edge cases           -> unit tests
#   - API error codes for bad input          -> API / integration tests
```

## A test drive, not a parts inspection

Unit tests inspect each part on the bench; an E2E test takes the assembled car for a drive around the block. You need both, but you cannot afford to drive every route.

**Quiz:** Which is the best use of an E2E test?

- [ ] Checking that a CSS class name is spelled correctly
- [ ] Checking every branch of a tax calculation function
- [x] Checking that a user can complete checkout from cart to confirmation
- [ ] Checking the return type of a helper function

*Answer:* Checking that a user can complete checkout from cart to confirmation. E2E tests are expensive, so spend them on critical journeys.
