有没有办法检测 PHPUnit 测试是否在后台 运行?
Is there a way to detect if a PHPUnit test is running in background?
PHPUnit 有 two special annotations 指示测试应该 运行 在后台进程中:影响当前 [=25= 中的所有测试的 class 注释 @runTestsInSeparateProcesses
],以及影响当前测试的测试注解@runInSeparateProcess
。
这在某些情况下很有用,当被测试的 class 需要打印一些输出时,它不会弄乱 PHPUnit 自己的输出。
所以,这是我的问题:TestCase class 是否知道这个事实?它知道什么时候 运行 正在后台运行吗?如果是这样,是否有检测方法?
我正在寻找类似 $this->isRunningOnBackground()
的东西。
我在文档中没有找到任何相关信息。
浏览 PHPUnit 的源代码,我在 TestCase class $runTestInSeparateProcess
中发现了一个 boolean protected 属性 ,当注释存在时它被设置为 true 。还有一个 $runClassInSeparateProcess
,但它设置为私有,因此您无法在子 class 上下文中访问它。
我们可以通过检查 setUp() 或 tearDown() 中的 if ($this->runTestInSeparateProcess) {...}
来检测后台测试是否 运行。
PHPUnit 有 two special annotations 指示测试应该 运行 在后台进程中:影响当前 [=25= 中的所有测试的 class 注释 @runTestsInSeparateProcesses
],以及影响当前测试的测试注解@runInSeparateProcess
。
这在某些情况下很有用,当被测试的 class 需要打印一些输出时,它不会弄乱 PHPUnit 自己的输出。
所以,这是我的问题:TestCase class 是否知道这个事实?它知道什么时候 运行 正在后台运行吗?如果是这样,是否有检测方法?
我正在寻找类似 $this->isRunningOnBackground()
的东西。
我在文档中没有找到任何相关信息。
浏览 PHPUnit 的源代码,我在 TestCase class $runTestInSeparateProcess
中发现了一个 boolean protected 属性 ,当注释存在时它被设置为 true 。还有一个 $runClassInSeparateProcess
,但它设置为私有,因此您无法在子 class 上下文中访问它。
我们可以通过检查 setUp() 或 tearDown() 中的 if ($this->runTestInSeparateProcess) {...}
来检测后台测试是否 运行。