为什么我需要这个?我在symfony项目上运行测试(并使用Zend fw),phpunit为所有受影响的文件生成三叶草。但我不希望看到symfony和Zend libs (以及其他所有第三方库)的报道。我只希望看到我的代码的覆盖率。或者可能是本应做三叶草的查看器?我正在使用hudson的三叶草插件,但它不支持查看特定来源。三叶草插件显示,我的代码只覆盖了20%,这是不正确的,因为它也考虑了symfony和Zend库。
顺便说一句,有没有别的方法可以达到这个目的?
发布于 2010-09-08 01:14:01
您需要为phpunit创建一个配置文件,在该配置文件中,您可以从代码覆盖率中排除特定的文件或目录。
示例文件如下所示:
<phpunit stopOnFailure="false">
<testsuite name="Name">
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../php</directory>
<exclude>
<file>../php/somefile.php</file>
<directory suffix=".php">../php/pdf</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-clover" target="target-dir/build/logs/clover.xml"/>
</logging>
</phpunit>使用上面的文件,../php下的所有内容(这是相对于测试所在的目录并从中执行phprun的目录)都包含在代码覆盖率中,除了文件../php/somefile.php和目录../php/pdf中所有扩展名为.php的文件。
将此文件命名为phpunit.xml,将其放入运行测试的同一目录中。如果您运行phpunit,它将获取conf。
如果不能使用此特定的文件名,可以从命令行给出名称
phpunit --configuration yourconf.xml有关phpunit配置文件的更多详细信息,请访问:http://phpunit.de/manual/3.7/en/appendixes.configuration.html
发布于 2012-10-05 18:29:59
我认为配置xml文件的过滤器注释必须由loggin节点包装:
如下所示:
<phpunit stopOnFailure="false">
<testsuite name="Name"></testsuite>
<logging>
<filter>
<whitelist>
<directory suffix=".php">../php</directory>
<exclude>
<file>../php/somefile.php</file>
<directory suffix=".php">../php/pdf</directory>
</exclude>
</whitelist>
</filter>
<log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-clover" target="target-dir/build/logs/clover.xml"/>
</logging>
https://stackoverflow.com/questions/3579980
复制相似问题