I'd like to keep running my unit tests in strict mode so that I'm aware of any exceptionally long tests easily, but at the same time the default timeout of 1s is not enough. Can I change it for all tests? I know I can set timeout for each class (and individual tests) using @short / @medium / @long
annotations, but is there something like that for all tests? Perhaps in phpunit.xml?
This is to avoid PHP_Invoker_TimeoutException: Execution aborted after 1 second
that happens once in a while.
The option can be enabled by setting wanted times in phpunit.xml. The times are in seconds.
Example:
<phpunit
strict="true"
timeoutForSmallTests="1"
timeoutForMediumTests="5"
timeoutForLargeTests="10"
>
// test suites
</phpunit>
Tests can be marked to be medium or large by marking actual tests functions like following
/**
* @medium
*/
public function testTestThing() {
$this->assertTrue(false);
}
EDIT: modern PHPUnit versions does not do these timeouts any more, and also changes the behaviour of strict mode generally by introducing separate flags for each thing previously covered by strict mode:
beStrictAboutTestsThatDoNotTestAnything="true"
checkForUnintentionallyCoveredCode="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
beStrictAboutChangesToGlobalState="true"
Unrelated warning: it also changes paths to tests in the XML config to be relative to the XML config file, as opposed to old default that paths are to be relative to current working dir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With