A PHPUnit extension that allows you to execute your test cases in a random order
PHP
Latest commit f35935d Aug 3, 2016 @fiunchinho committed on GitHub Merge pull request #19 from prymas007/master
Permalink
Failed to load latest commit information.
bin Find vendor autoloader when running from project root Sep 18, 2014
example_tests Basic assertions to check if setUp and setUpBeforeClass are being cal… Aug 23, 2014
src/PHPUnitRandomizer
.gitignore Increased range of versions that randomizer is compatible with May 9, 2016
README.md Improved README May 9, 2016
composer.json Increased range of versions that randomizer is compatible with May 9, 2016
phpunit.xml.dist order and seed arguments working for choosing the order from CLI Aug 20, 2014

README.md

phpunit-randomizer

A PHPUnit extension that allows you to execute your test cases in a random order. This way you can identify tests that depend on other tests because they share some state, like object state, or even database state. PHPUnit has an option to execute test cases in process isolation, but that takes a lot of time when you have many tests.

With this library, you don't have to modify any PHPUnit code. Just install it, and use the binary from the vendor folder (vendor/fiunchinho/phpunit-randomizer/bin/phpunit-randomizer) to run your tests, instead of using the default phpunit command.

Usage

The executable binary is under the bin folder and it works exactly the same as the default phpunit file, accepting the same arguments, except for one: The order argument.

$ bin/phpunit-randomizer -h

When you execute your tests using this library, you will get the same results as using a regular PHPUnit installation unless you use the --order rand parameter. Try executing the following:

$ bin/phpunit-randomizer --order rand

If you look to the output, you'll see that it says that the tests have been randomized using a random seed. If you don't specify any seed (like the example above), the seed will be calculated randomly every time you execute your tests. But if you want to repeat an specific order that is interesting to you (because it failed, for example), you can re-run that order specifing the seed in your order argument.

For example, let's try to execute the example tests (that print the name of the test case so we can see the order in which they are executed) twice, and see how the order differ.

Executing randomly your tests

Here you can see how the order of the test cases is different in the two executions. Also, you can see the seed used in both cases (8639 in the first one, 4674 in the second). Now, if we want to repeat the order of the second execution, we can select the same seed.

Executing randomly your tests

As you can see, the order is exactly the same.

PHPUnit