PHPUnit严格模式-如何更改默认超时 [英] PHPUnit strict mode - how to change default timeout

查看:63
本文介绍了PHPUnit严格模式-如何更改默认超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想继续在严格模式下运行我的单元测试,这样我就可以轻松地知道任何异常长的测试,但是同时默认的1s超时还不够.我可以为所有测试更改它吗?我知道我可以使用@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 second偶尔发生.

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严格模式-如何更改默认超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆