End-to-end tests
Tests that drive the real product like a user would.
End-to-end tests exercise the full stack through the interface. They are the closest to real use and the most fragile. A few covering critical paths, such as signup and payment, give the most value.
Why it matters for a product engineer
End-to-end tests use the product the way a person does: through the interface, with the whole stack behind it. They are the closest to real use, and the most fragile. A few tests on the paths that must never break, such as sign-up, sign-in and payment, give most of the value. Many more of them slow the team down and teach people to ignore red builds.
How to do it
- Choose the critical paths: where a failure costs money, data or trust.
- Write one test per path, from the user’s first step to the result they came for.
- Find elements the way users do, by role and visible text, not by CSS classes.
- Wait for conditions, such as a message on screen, never for a fixed time.
- Give each run its own account and data, and clean them up.
- Track flaky tests. Fix or remove a test that fails without a real bug.
Common mistakes
- Testing every edge case end to end, when a unit or integration test would do.
- Fixed sleeps that pass on a fast machine and fail in CI.
- Rerunning failures until they pass, so real bugs hide among flaky ones.
- Tests that depend on each other’s data.
Example
At Slack, mobile developers had 16,000+ automated tests on Android and 11,000+ on iOS. In July 2020, only 19.8% of builds on the main branch passed, and 56.8% of test jobs failed, often because of flaky tests. End-to-end tests were the flakiest. The team built a system that finds flaky and failing tests, suppresses them and opens a ticket for the owner. By February 2021, main branch builds passed 96% of the time.
Slack's mobile builds before and after automatic handling of flaky tests
- 56.8%
- Test jobs failing, Jul 2020
- 3.9%
- Test jobs failing, Feb 2021
- 96%
- Main branch builds passing, Feb 2021
- From 19.8% in Jul 2020
Flaky tests had made red builds normal. Removing them from the signal, with an owner to fix each one, made a red build mean something again.
MeasuredSlack Engineering, 5 Apr 2022
Sources: The practical test pyramid (Ham Vocke) ↗ · Handling flaky tests at scale: auto detection and suppression (Slack Engineering) ↗
Resources
1- articleGo deeper
The practical test pyramid ↗
Ham Vocke (martinfowler.com) · 2018 · 55 minA thorough, code-heavy guide to unit, integration and end-to-end tests and how many of each to write.
Tools
1- ToolOpen source