2017 © Pedro Peláez
 

library phpunit-randomizer

Execute your test cases in random order, so you can check if they have hidden dependencies

image

fiunchinho/phpunit-randomizer

Execute your test cases in random order, so you can check if they have hidden dependencies

  • Saturday, June 30, 2018
  • by fiunchinho
  • Repository
  • 4 Watchers
  • 46 Stars
  • 244,501 Installations
  • PHP
  • 36 Dependents
  • 1 Suggesters
  • 14 Forks
  • 1 Open issues
  • 15 Versions
  • 13 % Grown

The README.md

phpunit-randomizer

PHPUnit has now similar features to this plugin already built-in, so you wouldn't need to use this plugin. To execute your tests in a random order just, (*1)

vendor/bin/phpunit --order-by=random

You can pass a known seed to get the same order (useful when tests have failed in a certain order, so you can re-run the suite), (*2)

SEED=$(head -200 /dev/urandom | cksum | cut -f1 -d " ")
echo "Running tests with seed $SEED"
vendor/bin/phpunit --order-by=random --random-order-seed=$SEED

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., (*3)

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., (*4)

Installation

composer require --dev fiunchinho/phpunit-randomizer

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., (*5)

$ vendor/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:, (*6)

$ vendor/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., (*7)

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., (*8)

Executing randomly your tests, (*9)

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., (*10)

Executing randomly your tests, (*11)

As you can see, the order is exactly the same., (*12)

PHPUnit

The Versions

30/06 2018

dev-master

9999999-dev https://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

phpunit testing unit testing

09/05 2018

v4.0.0

4.0.0.0 https://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

phpunit testing unit testing

09/05 2018

v3.0.1

3.0.1.0 https://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

MIT

The Development Requires

phpunit testing unit testing

04/04 2018

dev-fiunchinho-patch-1

dev-fiunchinho-patch-1 https://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

MIT

The Development Requires

phpunit testing unit testing

03/04 2018

dev-add-license-1

dev-add-license-1 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

05/02 2017

v3.0.0

3.0.0.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

09/05 2016

v2.0.3

2.0.3.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

09/05 2016

dev-feature/increase_phpunit_version

dev-feature/increase_phpunit_version http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

19/12 2014

2.0.2

2.0.2.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

17/12 2014

dev-feature/increasing_phpunit_version

dev-feature/increasing_phpunit_version http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Development Requires

phpunit testing unit testing

23/08 2014

2.0.1

2.0.1.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Requires

 

phpunit testing unit testing

22/08 2014

2.0.0

2.0.0.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Requires

 

phpunit testing unit testing

19/08 2014

1.0.2

1.0.2.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Requires

 

phpunit testing unit testing

18/08 2014

1.0.1

1.0.1.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Requires

 

phpunit testing unit testing

17/08 2014

v1.0.0

1.0.0.0 http://armesto.net/

Execute your test cases in random order, so you can check if they have hidden dependencies

  Sources   Download

The Requires

 

phpunit testing unit testing