diff --git a/core/lib/Drupal/Core/Test/JUnitConverter.php b/core/lib/Drupal/Core/Test/JUnitConverter.php index 9bbf1b7c..c02b4572 100644 --- a/core/lib/Drupal/Core/Test/JUnitConverter.php +++ b/core/lib/Drupal/Core/Test/JUnitConverter.php @@ -142,6 +142,7 @@ public static function convertTestCaseToSimpletestRow($test_id, \SimpleXMLElemen 'function' => $attributes->class . '->' . $attributes->name . '()', 'line' => (int) $attributes->line ?: 0, 'file' => (string) $attributes->file, + 'time' => (float) $attributes->time, ]; return $record; } diff --git a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php index 58693bc8..38f9a665 100644 --- a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php +++ b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php @@ -227,6 +227,7 @@ public function execute(TestRun $test_run, array $unescaped_test_classnames, int 'function' => implode(",", $unescaped_test_classnames), 'line' => '0', 'file' => $phpunit_file, + 'time' => 0, ], ]; } @@ -271,9 +272,12 @@ public function summarizeResults(array $results): array { '#incomplete' => 0, '#exception' => 0, '#debug' => 0, + '#time' => 0, ]; } + $summaries[$result['test_class']]['#time'] += $result['time']; + switch ($result['status']) { case 'pass': $summaries[$result['test_class']]['#pass']++; diff --git a/core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php b/core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php index 2d7055a6..c058d430 100644 --- a/core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php +++ b/core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php @@ -253,6 +253,12 @@ public static function testingResultsSchema(): array { 'default' => '', 'description' => 'Name of the file where the function is called.', ], + 'time' => [ + 'type' => 'float', + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Time elapsed for the execution of the test.', + ], ], 'primary key' => ['message_id'], 'indexes' => [ diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 55cba669..3c3f8e3e 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -786,7 +786,8 @@ function simpletest_script_execute_batch(TestRunResultsStorageInterface $test_ru '#skipped' => 0, '#incomplete' => 0, '#exception' => 0, - '#debug' => 0 + '#debug' => 0, + '#time' => 0, ]); if ($args['die-on-fail']) { $test_db = new TestDatabase($child['test_run']->getDatabasePrefix()); @@ -1251,7 +1252,15 @@ function simpletest_script_reporter_display_summary($class, $results) { if ($results['#debug']) { $summary[] = $results['#debug'] . ' messages'; } - $output = vsprintf('%s %s', [$class_out, implode(', ', $summary)]); + + if ($results['#time']) { + $time = sprintf('%8.3fs', $results['#time']); + } + else { + $time = ' '; + } + + $output = vsprintf('%s %s %s', [$time, $class_out, implode(', ', $summary)]); $status = ($results['#fail'] || $results['#exception'] || $results['#risky'] ? 'fail' : 'pass'); simpletest_script_print($output . "\n", simpletest_script_color_code($status)); } diff --git a/core/tests/Drupal/Tests/Listeners/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/DrupalListener.php index b9bcd750..0909dd14 100644 --- a/core/tests/Drupal/Tests/Listeners/DrupalListener.php +++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php @@ -78,14 +78,14 @@ public function addError(Test $test, \Throwable $t, float $time): void { * {@inheritdoc} */ public function addWarning(Test $test, Warning $e, float $time): void { - $this->getJUnitListener()->addWarning($test, $t, $time); + $this->getJUnitListener()->addWarning($test, $e, $time); } /** * {@inheritdoc} */ public function addFailure(Test $test, AssertionFailedError $e, float $time): void { - $this->getJUnitListener()->addFailure($test, $t, $time); + $this->getJUnitListener()->addFailure($test, $e, $time); } /**