【发布时间】:2011-08-04 21:56:22
【问题描述】:
我正在使用 PHPUnit 3.5.14 并且有一套测试覆盖了我的 PHP 应用程序的 100%,不包括带有 // @codeCoverageIgnore[Start|End] 的某些部分。 HTML 覆盖率报告显示 100% 的覆盖率。但是,当我生成一份 Clover XML 覆盖率报告(我希望 Jenkins 阅读该报告以强制执行 100% 覆盖率要求)时,它会将我忽略的所有代码都显示为未覆盖。
例如,我有一个包含 20 个方法的控制器类,其中一个看起来像这样:
// @codeCoverageIgnoreStart
/**
* Gets an instance of Foo. Abstracted for testing.
*
* @param array $options The constructor argument
*
* @return Foo
*/
protected function _getFoo(array $options)
{
return new Foo($options);
}
// @codeCoverageIgnoreEnd
HTML 覆盖率报告显示了涵盖的 20 种方法,包括完全忽略的一种:
图片:报道摘录
但 Clover XML 报告显示涵盖了 19/20 种方法并且没有提及 _getFoo:
<class name="CampaignController" namespace="global" (...)>
<metrics methods="20" coveredmethods="19" conditionals="0" coveredconditionals="0" statements="532" coveredstatements="532" elements="552" coveredelements="551"/>
...
<line num="592" type="stmt" count="1"/>
<line num="593" type="stmt" count="1"/>
<line num="615" type="method" name="createAction" crap="2" count="2"/>
<line num="617" type="stmt" count="2"/>
(顶部的 _getFoo 行是第 596-608 行。)
我的 PHPUnit 配置的日志记录部分如下所示:
<logging>
<log type="coverage-html" target="../public/build/coverage" charset="UTF-8"
yui="true" highlight="true" lowUpperBound="90" highLowerBound="100"/>
<log type="coverage-clover" target="../public/build/test-coverage.xml"/>
</logging>
有没有办法配置 Clover 覆盖率日志条目,或者更改我的覆盖率忽略 cmets,以便 Clover 报告指示 100% 覆盖率以匹配 HTML 报告?
【问题讨论】:
标签: unit-testing phpunit code-coverage clover