【问题标题】:Exclude base directory from PHPUnit Code Coverage从 PHPUnit 代码覆盖中排除基目录
【发布时间】:2012-12-13 23:35:31
【问题描述】:

如何从 PHPUnit 的代码覆盖中排除基本目录?

这是我的 phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="include.php"
         stopOnError="false"
         stopOnFailure="false"
         stopOnIncomplete="false"
         stopOnSkipped="false">
    <testsuite name="MyProject">
        <directory>classes/*</directory>
    </testsuite>
    <logging>
        <log type="coverage-html" target="../reports/coverage" charset="UTF-8" yui="true" highlight="false" lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-xml" target="../reports/coverage.xml"/>
        <log type="test-xml" target="../reports/logfile.xml" logIncompleteSkipped="false"/>
        <log type="testdox-html" target="../reports/testdox.html"/>
        <log type="testdox-text" target="../reports/testdox.txt"/>
    </logging>
</phpunit>

当它输出时,它包括所有基本目录,如:

c:\work\some\path\MyProject

我怎样才能让它在代码覆盖率输出中只包含...\MyProject\*

【问题讨论】:

  • 你解决过这个问题吗?我也想知道怎么做,但不幸的是,写答案的人误解了你的问题。
  • @Julian 是的,我做到了,但那是前一阵子,所以我必须把它挖出来。

标签: php unit-testing phpunit code-coverage xdebug


【解决方案1】:

您的答案并没有真正描述您的项目布局,但我假设您正在寻找的是:

Including and Excluding Files for Code Coverage

这允许您指定 PHPUnit 在生成代码覆盖率时将关注的文件白名单。

不在该白名单上的所有内容都不会显示在报告中。

为此,请在顶层某处添加以下内容:

<filter>
  <whitelist processUncoveredFilesFromWhitelist="true">
    <directory suffix=".php">.../MyProject/</directory>
  </whitelist>
</filter>

【讨论】:

  • 对不起,如果我不清楚。我不想排除任何东西。我只想从代码覆盖率报告中删除基本目录。因此,例如,如果我现在运行测试并打开 CC 报告,我必须单击至少 5 个链接才能找到任何有意义的内容。 C:\ -> work -> projects -> websites -> MyProject -> classes。我只想在顶层拥有MyProject,所以我可以点击MyProject -> classes
  • 据我所知,有问题的&lt;filter&gt; 应该为您做到这一点。可能是 Windows 上的路径问题或一些奇怪的东西,但通常告诉 phpunit“这是覆盖的根文件夹”是这样完成的。
猜你喜欢
  • 2015-07-27
  • 1970-01-01
  • 2013-01-01
  • 2013-08-14
  • 1970-01-01
  • 2023-03-16
  • 2012-05-04
  • 2011-02-28
  • 1970-01-01
相关资源
最近更新 更多