All Projects → fiunchinho → phpunit-randomizer

fiunchinho / phpunit-randomizer

Licence: MIT license
A PHPUnit extension that allows you to execute your test cases in a random order

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to phpunit-randomizer

PhpUnitAssertException
Assert exception/throwable/error PHPUnit trait
Stars: ✭ 18 (-65.38%)
Mutual labels:  phpunit, phpunit-extension
think-phpunit
ThinkPHP5——phpunit测试用例
Stars: ✭ 17 (-67.31%)
Mutual labels:  phpunit
phpunit-detailed-printer
Detailed output formatter for PHPUnit tests
Stars: ✭ 39 (-25%)
Mutual labels:  phpunit
phpunit-documentation-chinese
Simplified Chinese Documentation for PHPUnit
Stars: ✭ 35 (-32.69%)
Mutual labels:  phpunit
vscode-phpunit
The VS Code Test Explorer extension for PHPUnit
Stars: ✭ 100 (+92.31%)
Mutual labels:  phpunit
phpunit-util
Helper package to ease testing with PHPUnit.
Stars: ✭ 18 (-65.38%)
Mutual labels:  phpunit
intellij-drupal-run-tests
Provides a run configuration that executes Drupal's test runner (for Simpletest, Unit, Kernel, Functional, FunctionalJavascript.)
Stars: ✭ 24 (-53.85%)
Mutual labels:  phpunit
laravel-survey
Laravel 6 survey app.
Stars: ✭ 39 (-25%)
Mutual labels:  phpunit
generator-composer
🐘 Yeoman (http://yeoman.io) generator for a PHP Composer project
Stars: ✭ 16 (-69.23%)
Mutual labels:  phpunit
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+19.23%)
Mutual labels:  phpunit
PHPUnit-Polyfills
Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests
Stars: ✭ 147 (+182.69%)
Mutual labels:  phpunit
composer-plugin-qa
Comprehensive Plugin for composer to execute PHP Quality assurance Tools
Stars: ✭ 25 (-51.92%)
Mutual labels:  phpunit
laravel-test-watcher
Laravel Test Watcher
Stars: ✭ 20 (-61.54%)
Mutual labels:  phpunit
mongounit
PHPUnit extension that enables MongoDB data fixtures for test cases.
Stars: ✭ 32 (-38.46%)
Mutual labels:  phpunit-extension
hubtel-payment
🎉A comprehensive PHP Client Package for consuming the Hubtel Payment API
Stars: ✭ 13 (-75%)
Mutual labels:  phpunit
specter-php
JSON Mocking and Testing for PHP
Stars: ✭ 18 (-65.38%)
Mutual labels:  phpunit
wordpress-plugin
WordPress plugin starter template with all of the things.
Stars: ✭ 19 (-63.46%)
Mutual labels:  phpunit
php-toolbox
🐳 A Docker image designed for PHP developers that care about code quality.
Stars: ✭ 18 (-65.38%)
Mutual labels:  phpunit
concise
✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
Stars: ✭ 47 (-9.62%)
Mutual labels:  phpunit
phpunit-documentation-russian
Russian Documentation for PHPUnit
Stars: ✭ 16 (-69.23%)
Mutual labels:  phpunit

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

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)

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.

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.

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.

$ 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:

$ 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.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].