Add a phpunit extension to flag slow tests
See https://aaronsaray.com/2021/finding-slow-tests-in-phpunit-9/
This commit is contained in:
parent
db9623395d
commit
c6953426d7
|
@ -49,4 +49,7 @@
|
|||
<file>./includes/wc-widget-functions.php</file>
|
||||
</exclude>
|
||||
</coverage>
|
||||
<extensions>
|
||||
<extension class="Automattic\WooCommerce\Tests\SlowTests" />
|
||||
</extensions>
|
||||
</phpunit>
|
||||
|
|
|
@ -287,6 +287,9 @@ class WC_Unit_Tests_Bootstrap {
|
|||
require_once $this->tests_dir . '/framework/traits/trait-wc-rest-api-complex-meta.php';
|
||||
require_once dirname( $this->tests_dir ) . '/php/helpers/HPOSToggleTrait.php';
|
||||
require_once dirname( $this->tests_dir ) . '/php/helpers/SerializingCacheTrait.php';
|
||||
|
||||
// Extensions.
|
||||
require_once dirname( $this->tests_dir ) . '/php/helpers/SlowTests.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Tests;
|
||||
|
||||
use Automattic\Jetpack\IdentityCrisis\Exception;
|
||||
use PHPUnit\Runner\AfterTestHook;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SlowTests implements AfterTestHook {
|
||||
/**
|
||||
* Threshold of what's considered "slow".
|
||||
*/
|
||||
protected const MAX_SECONDS_ALLOWED = 3;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $test Name of the test.
|
||||
* @param float $time Elapsed time in seconds of the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function executeAfterTest( string $test, float $time ): void {
|
||||
if ( $time > self::MAX_SECONDS_ALLOWED ) {
|
||||
fwrite( STDERR, sprintf( "\nThe %s test took %s seconds!\n", $test, $time ) );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue