Randomise your tests

A quick and easy way to ensure your tests don’t have any unwanted side-effects is to randomise the order in which they run. PHPUnit makes this easy.

<phpunit executionOrder="random"></phpunit>

Alternatively, you can pass the --order-by=random flag to the command-line test runner.

Try this with any sizeable test suite, and there’s a decent chance you’ll see a few unexpected failures.

Sign up for my newsletter

A monthly round-up of blog posts, projects, and internet oddments.