As you may know, Laravel and PHPUnit execute your tests sequentially within a single process. However, a single process doesn’t use multiple cores; therefore, your test execution is seriously bottlenecked!
To mitigate this issue, we're excited to announce that Parallel Testing is now available in Laravel. Starting Laravel v8.25, you may use the built-in
test Artisan command to run your tests simultaneously across multiple processes to significantly reduce the time required to run the entire test suite.
Using a solution built on top of Paratest, Laravel automatically handles creating and migrating a test database for each parallel process. Of course, other Laravel testing goodies - such as
Storage::fake - are ready to be used in Parallel too.
Each individual test suite will receive varying benefits from parallel testing. In this example above, test execution was reduced from 13 seconds to 2 seconds - 5x times faster.
1: To get started, first ensure you are running the latest version of Collision and Laravel 8:
composer update nunomaduro/collision laravel/framework
2: Then, include the
--parallel option when executing the
test Artisan command:
php artisan test --parallel
Be sure to check out the Parallel Testing documentation at laravel.com/docs. There, you will find the available parallel testing options and the information about how to prepare certain resources so they may be safely used by multiple test processes. If you are curious, you can also check the pull request that adds Parallel Testing into Laravel.
We hope you enjoy this new addition to Laravel. Happy testing!