--coverage-html时phpunit非常慢 [英] Phpunit very slow when --coverage-html
问题描述
Im使用Phpunit.如果我仅使用以下方式运行测试:
Im using Phpunit. If I just run my tests with:
phpunit --log-junit output.xml
phpunit --log-junit output.xml
这可以在一秒钟内完成.但是,如果我要覆盖代码:
this runs within a second. But if I want a code coverage:
phpunit --coverage-html ./report --log-junit output.xml
phpunit --coverage-html ./report --log-junit output.xml
然后非常缓慢,phpunit发送从 * .xml读取配置",挂起一分钟,然后开始执行测试
then its very slow, the phpunit sends "Configuration read from *.xml" and it hangs for a minute, then it start executing the tests
推荐答案
默认情况下,即使您为单个测试运行PHPUnit,PHPUnit也会评估配置的白名单中所有文件的覆盖范围.
By default, PHPUnit will evaluate the coverage of all files in your configured whitelist, even when you run PHPUnit for a single test.
如果白名单中有很多文件,这可能会增加代码覆盖范围的时间.
If you have a lot files in your whitelist, this can add a LOT of time to the generation of the code coverage.
通过将PHPUnit配置为将addUncoveredFilesFromWhitelist
属性设置为false
,可以将PHPUnit配置为仅为您编写/执行测试的文件生成代码覆盖率,从而加快处理速度.
You can speed things up by configuring PHPUnit to generate code coverage only for the files you have written/execute tests for, by setting the addUncoveredFilesFromWhitelist
attribute to false
.
<phpunit>
<!-- ... -->
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<!-- ... -->
</whitelist>
</filter>
</phpunit>
在禁用此设置的情况下,您应该看到生成的代码覆盖率文件仅描述了针对其运行测试的文件.
With this setting disabled, you should see that the resulting code coverage files only describe the files you ran the tests for.
请注意, PHPUnit文档建议addUncoveredFilesFromWhitelist
默认为false
,但在5.5版上,默认情况下为true
.
Note that the PHPUnit documentation suggests addUncoveredFilesFromWhitelist
is false
by default, but on version 5.5 it appears to be true
by default.
这篇关于--coverage-html时phpunit非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!