您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-timeoutForSmallTests
发布时间:2021-10-17 18:44:25编辑:雪饮阅读()
timeoutForMediumTests 属性
可能值:整数(默认值:10)
此属性配置标注为 @medium 的测试的时间限制(以秒为单位)。
另外一点就是必须结合enforceTimeLimit为true才方便测试timeoutForSmallTests。
那么有如下程序:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @small
*/
public function testOne(): void
{
sleep(10);
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(true);
}
public function testThree(): void
{
$this->assertTrue(true);
}
}
这里第一个测试方法用了@small标注,并且休眠了10秒,显然超过了默认的1秒
phpunit.xml:
<phpunit bootstrap="src/autoload.php" enforceTimeLimit="true">
</phpunit>
那么接下来的运行结果:
[root@localhost organizing]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar -c /usr/local/organizing/phpunit.xml /usr/local/organizing/tests/MyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
RR. 3 / 3 (100%).
Time: 00:01.001, Memory: 18.00 MB
There were 2 risky tests:
1) MyTest::testOne
Warning: include(PHPUnit\Composer\Autoload\ClassLoader.php): failed to open stream: No such file or directory in /usr/local/organizing/src/autoload.php on line 3
Warning: include(): Failed opening 'PHPUnit\Composer\Autoload\ClassLoader.php' for inclusion (include_path='.:/usr/local/php734/lib/php') in /usr/local/organizing/src/autoload.php on line 3
Execution aborted after 1 second
2) MyTest::testOne
This test did not perform any assertions
/usr/local/organizing/tests/MyTest.php:8
OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 2, Risky: 2.
这里就提示了超过默认配置的1秒的限制了。
那么phpunit.xml修改如:
<phpunit bootstrap="src/autoload.php" enforceTimeLimit="true" timeoutForSmallTests="5">
</phpunit>
然后再次运行:
[root@localhost organizing]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar -c /usr/local/organizing/phpunit.xml /usr/local/organizing/tests/MyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
RR. 3 / 3 (100%).
Time: 00:05.004, Memory: 18.00 MB
There were 2 risky tests:
1) MyTest::testOne
Warning: include(PHPUnit\Composer\Autoload\ClassLoader.php): failed to open stream: No such file or directory in /usr/local/organizing/src/autoload.php on line 3
Warning: include(): Failed opening 'PHPUnit\Composer\Autoload\ClassLoader.php' for inclusion (include_path='.:/usr/local/php734/lib/php') in /usr/local/organizing/src/autoload.php on line 3
Execution aborted after 5 seconds
2) MyTest::testOne
This test did not perform any assertions
/usr/local/organizing/tests/MyTest.php:8
OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 2, Risky: 2.
这次有提示了5秒的限制,不过时间方面大家都心知肚明,一般都是有误差的。
关键字词:phpunit,timeoutForSmallTests
相关文章
- phpunit-phpunit.xml-phpunit的enforceTimeLimit与def
- phpunit-phpunit.xml-phpunit-beStrictAboutTodoAnnot
- phpunit-phpunit.xml-beStrictAboutTestsThatDoNotTes
- phpunit-phpunit.xml-phpunit-beStrictAboutOutputDur
- phpunit-phpunit.xml-phpunit-stopOnDefect
- phpunit-phpunit.xml-stopOnSkipped
- phpunit-phpunit.xml-phpunit-stopOnRisky
- phpunit-phpunit.xml-phpunit-stopOnIncomplete
- phpunit-phpunit.xml-phpunit-stopOnFailure
- phpunit-phpunit.xml-phpunit-stopOnError