Coding

End to End Testing Explained: What It Is and How to Start

End to end testing checks that a complete application works the way a user would use it, with all its parts connected: front end, back end, database and any services. A test script opens the app, performs a real journey such as signing in or checking out, and asserts on what the user would see.

What end to end testing covers

Martin Fowler defines a broad-stack test, his name for the same thing, as one that "exercises most of the parts of a large application". The practical test pyramid article describes end to end tests as testing your deployed application via its user interface. Because everything runs together, these tests can find bugs in the interaction between components that tests of a single component cannot.

The boundary is not sharp. Fowler describes it as a continuum: a test that drives the application through a service interface rather than a screen can still be broad-stack if it exercises most of the system.

End to end tests compared with unit and integration tests

Unit testIntegration testEnd to end test
ScopeOne function or classA few components togetherMost of the application
Entry pointCode callCode call, often with a real databaseUsually the UI or public API
SpeedFastestSlowerSlowest
Confidence it works for usersLowestMediumHighest
Maintenance costLowMediumHighest
How manyManyFewerFewest

The rows for speed, confidence and count follow the test pyramid as Fowler describes it. End to end tests give "the biggest confidence" that the software works, but they "require a lot of maintenance and run pretty slowly".

When to write an end to end test

Write them for the journeys that deliver your product's main value, where a failure would be a serious problem. Fowler's example for an online shop is searching for a product, adding it to the basket and checking out. A typical short list:

  • Sign up and sign in.
  • The main purchase, booking or submission flow.
  • Any path where several services must cooperate and no lower-level test sees the whole chain.

Leave edge cases to lower levels. Fowler warns that repeating them at the top "will slow you down and cause you to lose trust in your tests." Validation rules, rounding and error messages are cheaper to test with unit tests, which fail with a pointer to the exact function.

Why end to end tests are flaky, and what to do about it

Fowler's article lists the drawbacks plainly: they are "notoriously flaky and often fail for unexpected and unforeseeable reasons", and failures are often false positives. In a system of many services you may not be able to run them locally, and no single team owns them. Ways to reduce the pain:

  • Keep the count small. Fowler's advice is to reduce them to a bare minimum.
  • Do not call third-party systems. Fowler calls tests that hit remote systems "unnecessarily slow and brittle" and prefers test doubles, with contract tests to check the doubles. Playwright's best practices say the same: test only what you control, and mock the response with the network API.
  • Isolate every test. Playwright says each test should be completely isolated from another and run independently.
  • Wait for conditions, not for time. Use assertions that retry until the condition is met, instead of fixed sleeps.

A first end to end test with Playwright

Playwright is one of several browser automation tools for this job. Its installation guide gives this command, which creates a project or adds Playwright to an existing one:

npm init playwright@latest

It creates playwright.config.ts, and an example test at tests/example.spec.ts (the folder is named e2e if tests already exists). Run all tests with:

npx playwright test

By default Playwright runs tests headless and in parallel on Chromium, Firefox and WebKit. You can change that in the config file.

Here is a sketch of a sign-in journey. The address, labels and text are placeholders for your own app, so adapt them before running it:

import { test, expect } from '@playwright/test';

test('user can sign in and see their dashboard', async ({ page }) => {
  await page.goto('http://localhost:3000/login');
  await page.getByLabel('Email').fill('[email protected]');
  await page.getByLabel('Password').fill(process.env.TEST_PASSWORD ?? '');
  await page.getByRole('button', { name: 'Sign in' }).click();
  await expect(page.getByText('Welcome back')).toBeVisible();
});

Three habits from the Playwright best practices show up in that test:

  • Test what the user sees. Locators such as getByRole('button', { name: 'submit' }) use user-facing attributes, which Playwright recommends over CSS or XPath because the DOM structure changes often.
  • Use web-first assertions. await expect(...).toBeVisible() waits until the condition is met. Checking isVisible() by hand returns immediately without waiting.
  • Use a test account. Read credentials from an environment variable, never hard-code a real password, and use fake data for everything else. The larely test data generator produces fake names and emails as CSV or JSON.

Mocking a third-party call

When a journey touches a service you do not control, Playwright's documentation shows intercepting the request and returning a fixed response:

await page.route('**/api/fetch_data_third_party_dependency', route => route.fulfill({
  status: 200,
  body: testData,
}));

This keeps the test deterministic while the rest of the application still runs for real.

If your end to end tests keep failing

  • Passes locally, fails in CI: the test probably depends on timing or leftover state. Make each test create its own data and use retrying assertions.
  • Fails on only one run in many: look for a hidden shared dependency, such as a third-party call or data from another test, and mock or isolate it.
  • The suite is slow: count how many tests repeat the same journey, and move edge cases down to unit or integration tests.

Frequently asked questions

What is the difference between end to end testing and integration testing?
An integration test checks that a few components work together, such as your code and a real database. An end to end test runs the whole application with its parts connected and drives it from the outside, usually through the user interface, so it covers a complete user journey.
Why are end to end tests flaky?
They depend on many moving parts at once: a browser, a running server, a database, the network and often other services. Any of these can fail or respond slowly for reasons unrelated to your change. Martin Fowler's test pyramid article calls them notoriously flaky and says their failures are often false positives.
How many end to end tests should I write?
As few as cover your core user journeys. Fowler's article says to reduce them to a bare minimum because of their maintenance cost, and gives search, add to basket and checkout as the kind of journey worth covering. Test edge cases in faster, lower-level tests instead.
Is end to end testing the same as UI testing?
Not exactly. Most end to end tests drive the user interface, but the defining feature is that they exercise most of the application together. Fowler notes the line is a continuum: a test that drives the whole system through a service interface instead of a UI can still count as an end to end test.

Sources