我有一個PHPUnit測試,測試名爲HelpTokenizerTest的類。這個類實現TokenizerInterface。由於某種奇怪的原因,我無法從代碼覆蓋範圍中排除TokenizerInterface。從PHPUnit代碼覆蓋率中排除PHP接口
儘管使用@codeCoverageIgnore或者甚至@ codeCoverageIgnoreStart/End,它在代碼覆蓋率報告中未顯示。
任何想法?
我不希望接口包含在我的測試覆蓋範圍內,因爲它什麼都不做。測試接口有什麼意義。
我有一個PHPUnit測試,測試名爲HelpTokenizerTest的類。這個類實現TokenizerInterface。由於某種奇怪的原因,我無法從代碼覆蓋範圍中排除TokenizerInterface。從PHPUnit代碼覆蓋率中排除PHP接口
儘管使用@codeCoverageIgnore或者甚至@ codeCoverageIgnoreStart/End,它在代碼覆蓋率報告中未顯示。
任何想法?
我不希望接口包含在我的測試覆蓋範圍內,因爲它什麼都不做。測試接口有什麼意義。
使用phpunit.xml時,您可以設置過濾器來排除具有特定名稱的文件,特別是文件夾或具有特定擴展名的文件。
例子:
<testsuite name="Application Test Suite">
<directory>./application/</directory>
</testsuite>
<filter>
<blacklist>
HERE
</blacklist>
or alternatively
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>
<exclude>
AND HERE
<directory suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
請注意,如果您定義白名單,PHPUnit將忽略黑名單,因此您必須在白名單中使用「
這就是我最終做的。感謝塞繆爾和大衛! – 2011-06-02 22:19:11
您可以使用@codeCoverageIgnore爲註釋在文件的開頭獲得100% 0/0覆蓋。
<?php // @codeCoverageIgnoreStart
interface MyInterface
{
public function myfunction();
}
請注意,它不起作用的評論塊。
問題上PHPUnit的github上開:https://github.com/sebastianbergmann/phpunit/issues/497
您使用XML配置或測試套件? – 2011-06-02 21:52:13