I have a contrived test case showcasing how multiple test cases can slow the entire execution time down, as even though each is quick on its own, they add up if waited for before executing the next.
use PHPUnitFrameworkTestCase;
class ShouldTestInParallel extends TestCase
{
/**
* @dataProvider delayProvider
*/
public function testItRunsTestsInParallel(int $delay)
{
sleep($delay);
$this->assertTrue(true);
}
public function delayProvider()
{
return array_map(function ($value) {
return [$value];
}, array_fill(0, 10, 1));
}
}
In order speed up test execution time, I installed paratest
:
composer require brianium/paratest --dev
Now I expected the test to finish after 1 seconds.
I execute the test via phpstorm (and have enabled the paratest config), yet the entire test run still takes ~10s as each test is executed one after the other.
/bin/php -d memory_limit=5G /myproject/vendor/bin/paratest_for_phpstorm /myproject/library/vendor/phpunit/phpunit/phpunit --bootstrap /myproject/tests/bootstrap.php --debug --verbose --configuration /myproject/tests/phpunit.xml --filter Test\Vm\ShouldTestInParallel --test-suffix ShouldTestInParallel.php /myproject/tests/Vm --teamcity
Testing started at 1:57 PM ...
PHPUnit 9.6.25 by Sebastian Bergmann and contributors.
Runtime: PHP 8.0.30
Configuration: /myproject/tests/phpunit.xml
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #0 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #1 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #2 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #3 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #4 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #5 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #6 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #7 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #8 (1)' ended
Test 'TestVmShouldTestInParallel::testItRunsTestsInParallel with data set #9 (1)' ended
Time: 00:10.026, Memory: 28.00 MB
OK (10 tests, 10 assertions)
Process finished with exit code 129 (interrupted by signal 1:SIGHUP)