Notes
The maths
Here is why scale changes things. One test that flakes one time in a thousand is barely noticeable. Three thousand tests, each flaking one time in a thousand, means the chance that a run is fully green is zero point nine nine nine to the power of three thousand, about five percent. Ninety five percent of runs would show a false red. Reliability is a property of the whole suite, so tiny per test flake rates matter enormously.
1 test, 0.1% flaky:
fails 1 run in 1,000
3,000 tests, each 0.1% flaky:
P(all pass) = 0.999^3000
≈ 5%
→ 95% of runs have a false red
reliability is a property of
the whole suite, not one test Isolation
The foundation is isolation. Each test gets a fresh world. Playwright gives each test a new browser context by default, with its own cookies, storage and cache, like a brand new incognito window. Each test creates its own user and data, uses no shared static state, and never relies on the order tests run in. It costs a little setup time, and buys the ability to run tests in any order, on any machine, in parallel.
- Playwright: a new browser context per test: fresh cookies, storage, cache
- own data: unique user, cart
- no shared static state
- no reliance on test order
- cost: a little setup time
- payoff: any order, any machine, in parallel
Parallel and shards
Isolated tests can run in parallel. Workers run tests side by side on one machine: in Playwright, set fully parallel and a number of workers; in pytest, the xdist plugin's dash n auto; in JUnit five, switch on parallel execution. Sharding splits the suite across machines: Playwright's shard two of five runs the second fifth. A forty minute suite on five shards takes about eight. Part eight sets this up in CI.
# Playwright fullyParallel: true, workers: 4 npx playwright test --shard=2/5 # pytest pytest -n auto (pytest-xdist) # JUnit 5 junit.jupiter.execution .parallel.enabled=true 40 min / 5 shards ≈ 8 min
Shuffle
Tests that pass in one order can hide dependencies: test B quietly relies on data test A created. Shuffling the order exposes them. Recent Playwright versions have a shuffle option, and you can pass a seed to replay the same order. pytest has random order plugins. When a test fails only in a certain order, you have found a hidden dependency. Keep the seed from the failing run so you can reproduce it exactly.
# Playwright (2026) npx playwright test --shuffle --shuffle 1234 # replay # pytest pytest --random-order (pytest-random-order) a failure only in one order = hidden dependency keep the seed to reproduce
Locks
Sometimes a resource really is shared. ShopRung's bug switch is global: if two tests flip it at the same time, they break each other. Rather than running the whole suite one test at a time, lock just those tests. Recent Playwright versions let a group of tests declare a named lock, so tests with the same lock never overlap while everything else stays parallel. Other tools use serial groups or resource tags. Lock the few, run the rest in parallel.
// tests touching one shared
// resource must not overlap
test.describe.configure({
lock: "bug-switch" });
ShopRung: the bug switch is
GLOBAL; two tests flipping it
at once break each other
lock the few, parallel the rest Isolated retries
If you retry, retry honestly. A retry in the same worker may pass or fail because of state left behind by the first attempt. Retrying in a fresh, isolated worker gives a cleaner answer, and recent Playwright versions offer that as a retry strategy. Either way, the report should say flaky, not passed, for a test that needed a retry, and each flaky result should become a ticket. Retries keep the pipeline moving; they do not make the problem go away.
- retry in a FRESH worker, so leftover state from the failure does not decide the retry (Playwright 2026: retryStrategy: "isolated")
- report: passed / failed / FLAKY
- flaky is a bug with a ticket, not a pass
Flakes cluster
Flaky tests rarely fail alone. A 2025 study of twenty four Java projects found that three quarters of eight hundred and ten flaky tests failed in clusters that shared a cause. One slow service, one shared fixture, or one too short timeout can make thirty tests flake together. So group failures by their error and their timing. Fixing one root cause can clear dozens of flaky tests at once, which is far cheaper than fixing them one by one.
- research on 24 Java projects (2025): 75% of 810 flaky tests failed in clusters with a shared cause
- one slow service, one shared
- fixture, one timeout value → 30 tests flake together
- group failures by cause
Treat flakiness as data
At scale, run reliability like a product. A dashboard shows the flake rate per test, per suite and per team over time. Tests above a threshold are quarantined automatically, with a ticket. Every test has an owner. Set budgets, for example a suite that is fully green on at least ninety eight percent of clean runs, and finishes in under fifteen minutes per pull request. Review the ten worst tests every week. What gets measured gets fixed.
- dashboard: flake rate per test, suite, team, over time
- auto-quarantine above a threshold, with a ticket
- every test has an owner
- budget: e.g. suite green rate above 98%
- suite time budget: e.g. under 15 minutes per PR
- review the worst 10 weekly
Common mistakes
Scale mistakes. Switching on parallel runs before tests are isolated, which turns hidden dependencies into random failures. One shared test account for everything. Global switches, like feature flags or ShopRung's bug switch, without locks. Retries that hide flakes in a green report. Tests with no owner. Shards split by file count instead of run time, so one shard takes three times longer than the others. And never shuffling, so hidden dependencies stay hidden.
- running in parallel before tests are isolated
- one shared test account
- global switches without locks
- retries that hide flakes
- no owner per test
- sharding by file count, not by run time
- never shuffling the order
Say it like this
In a senior interview: isolation first, with a fresh browser context and its own data for every test. Then parallel workers and shards for speed, shuffled order to find hidden dependencies, locks only for truly shared resources, and retries in a fresh worker that are reported as flaky, not passed. On top, a flake dashboard with owners and budgets, and since flakes cluster, I fix shared causes first.
- "Isolation first: fresh
- context and own data per test. Then parallel workers
- and shards, shuffled order to find hidden dependencies, locks only for truly shared
- resources, retries in a fresh
- worker reported as flaky, and a flake dashboard with owners, fixing shared causes first."