End-to-end testing
Testing a real, running Angular app from the outside with Playwright or Cypress — and what unit tests were never meant to cover.
End-to-end testing
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- An end-to-end test drives a real, running app through an actual browser — clicking real buttons, filling real inputs — completely outside Angular's own TestBed machinery.
- A unit test verifies one piece in isolation; an end-to-end test verifies that real pieces, wired together exactly as they are in production, actually work for a user.
- A healthy test suite leans heavily toward unit tests and uses a smaller number of end-to-end tests for the critical paths — e2e tests run slower and break for more unrelated reasons, which makes a suite made of nothing but them expensive to maintain.
Leaving TestBed entirely
Every test so far in this roadmap has operated inside Angular’s own testing
machinery — TestBed constructing a component or service in a simulated
environment, HttpTestingController faking network responses. An end-to-end
test throws all of that away and does the opposite: it drives a real,
actually-running instance of your app, in an actual browser, clicking real
buttons and filling real form fields, with real navigation and (depending on
setup) real or realistically-mocked network calls. Nothing about Angular’s
internals is visible to this kind of test at all — as far as it’s concerned,
it’s just a browser pointed at a URL.
import { test, expect } from '@playwright/test';
test('user can log in and see their dashboard', async ({ page }) => {
await page.goto('/login');
await page.fill('[name=email]', 'user@example.com');
await page.fill('[name=password]', 'correct-password');
await page.click('button[type=submit]');
await expect(page).toHaveURL('/dashboard');
await expect(page.locator('h1')).toContainText('Welcome back');
});
This test knows nothing about LoginComponent’s internals, its FormGroup, or
any TestBed setup. It knows a URL, some selectors, and what should be true
after a sequence of real interactions — the same thing a human tester clicking
through the app would check.
Verifying the whole is wired together, not just that each part works
This is the actual gap unit tests leave open. Every component and service can individually pass every unit test — each piece, in isolation, does exactly what it claims to — and the real app can still be broken for an actual user, because something about how those pieces are wired together is wrong: a route that’s misconfigured, a provider missing from the real bootstrap, an assumption about an API response that doesn’t match what the real backend actually returns. Unit tests, by design, don’t exercise that integration at all; an end-to-end test is specifically built to.
Why not just write end-to-end tests for everything
Given that framing, it’s tempting to wonder why unit tests matter at all if end-to-end tests catch the “does it actually work” question more directly. The honest answer is cost: a real browser, real navigation, often real or realistic network calls — every one of those is slower than a unit test by orders of magnitude, and more prone to failing for reasons that have nothing to do with the thing you meant to test (a slow network, a flaky third-party script, a timing race). The standard, well-earned advice is a pyramid shape: many fast, precise unit tests covering individual pieces, and a smaller number of end-to-end tests reserved specifically for the critical user journeys worth paying that slower, broader cost for.
Dealing with a real backend inside an e2e test
An honest wrinkle worth naming: an end-to-end test driving a real, running app still has to decide what that app talks to on the backend. Pointing it at a genuine production or shared staging API makes tests slow, flaky (shared state another test run might have changed), and risky if a test accidentally creates or deletes real data. The common middle ground is a dedicated test environment with seeded, predictable data — or intercepting network calls at the browser level (both Playwright and Cypress support this directly) to return fixed, controlled responses for specific requests while still driving the real, rendered UI around them. Which approach fits depends on how much of the real backend’s behavior you actually need the test to verify versus how much you’re willing to fake for speed and determinism.
This lesson’s video makes a direct, current case for Playwright specifically — the increasingly preferred tool over the older default of Cypress — framed around real ROI rather than tooling preference alone; the linked “deeper” video covers the Cypress approach to the same problem if you encounter it in an existing codebase.
Check yourself
Why can a component's unit tests all pass while the real, assembled app is still completely broken for a user?
Unit tests, including the TestBed-based ones from earlier in this roadmap, test pieces in isolation — a component rendered on its own, a service called directly. They say nothing about whether those pieces are correctly wired together at the app level: a missing route, a misconfigured provider, an API contract mismatch between a real backend and what the frontend expects. An end-to-end test is what actually exercises the real, assembled app end to end, the way a user would experience it.
Why wouldn't a healthy test suite consist entirely of end-to-end tests, if they're the ones that most directly verify real user-facing behavior?
End-to-end tests are slow (driving a real browser through real navigation and network calls) and more brittle — they can fail for reasons entirely unrelated to the thing you're actually trying to verify, like a flaky network call or a timing issue in a third-party widget. Unit tests are fast and precise about what broke; the standard advice is many unit tests covering individual pieces, with a smaller number of end-to-end tests reserved for the critical user paths worth that slower, broader coverage.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.