您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-timeoutForMediumTests
发布时间:2021-10-17 18:51:56编辑:雪饮阅读()
timeoutForMediumTests 属性
可能值:整数(默认值:10)
此属性配置标注为 @medium 的测试的时间限制(以秒为单位)。
另外timeoutForMediumTests的测试要依托于enforceTimeLimit为true才能方便测试。
看看如下程序:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
/**
* @medium
*/
public function testOne(): void
{
sleep(20);
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(true);
}
public function testThree(): void
{
$this->assertTrue(true);
}
}
这里用medium标注了第一个测试方法,并且第一个测试方法休眠了20秒,很显然超过了timeoutForMediumTests默认的10秒。
那么配置文件:
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:10.002, 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 10 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.
那么此时也就有提示10秒的限制。
那么假如配置文件:
phpunit.xml修改如:
<phpunit bootstrap="src/autoload.php" enforceTimeLimit="true" timeoutForMediumTests="15">
</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:15.002, 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 15 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.
这里提示了15秒的限制,那么因为程序里面第一个测试方法休眠了20秒,自然也是超过配置文件中的15秒的。
关键字词:phpunit,timeoutForMediumTests
相关文章
- phpunit-phpunit.xml-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