Agent Wranglers

TST-27Recommended

Find hidden order dependencies

Run tests in a random order, so tests that depend on each other fail early.

How to do it

Turn on random order in the runner, such as Vitest --sequence.shuffle, Jest --randomize, pytest-randomly or PHPUnit --order-by=random. Print the seed, or set it yourself, so a failing order can be run again. Shared module state is a common cause, so pass state in instead of sharing globals.

Examples

Shell example

npx vitest run --sequence.shuffle --sequence.seed=20261020
npx jest --randomize --seed=20261020
pytest -p randomly --randomly-seed=20261020

How to check

The test command shuffles the order and logs the seed. Running it again with that seed repeats the same order.

Sources

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/random-order">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.