PHPUnit strict mode - how to change default timeout(PHPUnit 严格模式 - 如何更改默认超时)
问题描述
我想继续在严格模式下运行我的单元测试,这样我就可以轻松地发现任何异常长的测试,但同时默认的 1 秒超时是不够的.我可以为所有测试更改它吗?我知道我可以使用 @short/@medium/@long
注释为每个类(和单个测试)设置超时,但是所有测试都有类似的东西吗?也许在 phpunit.xml 中?
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?
这是为了避免 PHP_Invoker_TimeoutException: Execution aborted after 1 seconds
偶尔发生.
This is to avoid PHP_Invoker_TimeoutException: Execution aborted after 1 second
that happens once in a while.
推荐答案
可以通过在 phpunit.xml 中设置想要的时间来启用该选项.时间以秒为单位.
The option can be enabled by setting wanted times in phpunit.xml. The times are in seconds.
例子:
<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);
}
现代 PHPUnit 版本 不再执行这些超时,并且通常通过为每个事物引入单独的标志来改变严格模式的行为 之前被严格模式覆盖:
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"
不相关的警告:它还将 XML 配置中的测试路径更改为相对于 XML 配置文件,而不是旧的默认路径相对于当前工作目录.
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.
这篇关于PHPUnit 严格模式 - 如何更改默认超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHPUnit 严格模式 - 如何更改默认超时
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01