TST-30Recommended
Keep the suite within a time budget
Set a time limit for the whole suite and for each kind of test. Examples are 30 seconds for unit tests and ten minutes for the whole suite. Treat going over it as a failure.
How to do it
Run tests in parallel, such as pytest-xdist -n auto, Playwright workers or sharding across machines. Run timing checks, such as load tests, alone afterwards, because other steps on the same machine slow them and they fail at random. Track the slowest tests and fix them first. A suite that takes too long gets skipped, which is worse than a smaller suite. Run independent steps at the same time. For pages made from one template, check every template plus the riskiest pages and a seeded random sample, and sweep everything in CI. Batch requests in tests, and skip work a test does not need, such as compression.
Examples
Shell example
pytest -n auto --durations=20
npx playwright test --shard=1/4
How to check
The pipeline records each stage's duration and sets a time limit on each, such as timeout-minutes in GitHub Actions or timeout 600 in a script. The run fails when a stage passes its limit.
Measured
On a reference site, the full check went from 12 minutes to about 70 seconds. Steps ran in parallel, and the browser check sampled pages of one template. Its load test, run beside the browser check, failed with a 95th percentile from 42 to 3,874 ms. Run alone, it passed.
Sources
Related rules
- ENG-5 Unit test every branch and calculation in Engineering
- TST-2 Keep most tests small and fast in Testing
- TST-9 Keep unit tests fast in Testing
- TST-17 Test every critical journey end to end in Testing
- TST-56 Run the tests a change affects on every pull request in Testing
- TST-59 Give every test its own time limit in Testing
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/suite-time-budget">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.