-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
| Q | A |
|---|---|
| PHPUnit version | 12.0.x |
| PHP version | 8.3.x |
| Installation Method | Composer |
Summary
When running PHPUnit 12, the very first test is reported to have a time-consumption really higher than with PHPUnit 11 on JUnit and cache-files reports. I bet this might be caused by an unwanted including of tests preparations before the very first test plays, but I can't find any location in source code so I wasn't able to provide a PR about it.
Current behavior
The "time" value on JUnit report is currently not the actual execution time for the very first test only.
On PHPUnit 12.0.10 :
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="/data/www/phpunit.xml" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.452475">
<testsuite name="myproject" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.452475">
<testsuite name="MyProject\Tests\FooBarTest" file="/data/www/src/Tests/FooBarTest.php" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.452475">
<testsuite name="MyProject\Tests\FooBarTest::testTrue" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.452475">
<testcase name="testTrue with data set "test-case #1"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.445116"/>
<testcase name="testTrue with data set "test-case #2"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.003829"/>
<testcase name="testTrue with data set "test-case #3"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.003530"/>
</testsuite>
</testsuite>
</testsuite>
</testsuite>
</testsuites>On PHPUnit 11.5.15 :
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="/data/www/phpunit.xml" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.074995">
<testsuite name="myproject" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.074995">
<testsuite name="MyProject\Tests\FooBarTest" file="/data/www/src/Tests/FooBarTest.php" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.074995">
<testsuite name="MyProject\Tests\FooBarTest::testTrue" tests="3" assertions="3" errors="0" failures="0" skipped="0" time="0.074995">
<testcase name="testTrue with data set "test-case #1"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.066512"/>
<testcase name="testTrue with data set "test-case #2"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.004285"/>
<testcase name="testTrue with data set "test-case #3"" file="/data/www/src/Tests/FooBarTest.php" line="17" class="MyProject\Tests\FooBarTest" classname="MyProject.Tests.FooBarTest" assertions="1" time="0.004197"/>
</testsuite>
</testsuite>
</testsuite>
</testsuite>
</testsuites>How to reproduce
Simply create a very simple test case and compare the execution time with actual time, or with PHPUnit 11.
PHP Test file used for given stats:
<?php declare(strict_types=1);
namespace MyProject\Tests;
final class FooBarTest extends \PHPUnit\Framework\TestCase
{
public static function provideTest(): \Generator
{
yield 'test-case #1' => ['a'];
yield 'test-case #2' => ['b'];
yield 'test-case #3' => ['c'];
}
#[\PHPUnit\Framework\Attributes\DataProvider('provideTest')]
public function testTrue(): void
{
self::assertTrue(true);
}
}Expected behavior
The "time" value on JUnit report should reflects the actual execution time of the test and not include the data preparation, like for PHPUnit 11
Thank you very much 🙂