如何通过 Netbeans / PHPStorm / PHPUnit 集成从代码覆盖率中排除文件/代码块
要求:
- 带有 PHPUnit(6.9) 的 Netbeans
- 编辑: 例如,同样适用于 PHPStorm
如何:
- 从代码覆盖率中排除行。
- 从代码覆盖率中排除代码块(行)。
Requirements:
- Netbeans with PHPUnit(6.9)
- EDIT: Same applies, for example, to PHPStorm
How to:
- Exclude lines from code coverage.
- Exclude code blocks (lines) from code coverage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
忽略方法代码块:
忽略类代码块:
正如 @david-harkness 所说,忽略单独的行:
更多信息可以在 忽略代码块标题下的 PHPUnit 文档。
To ignore method code blocks:
To ignore class code blocks:
And as @david-harkness said, to ignore individual lines:
More information can by found in the PHPUnit Documentation under the Ignoring code blocks heading.
如果您试图实现 100% 的代码覆盖率,但有一行或多行无法测试,则可以使用特殊注释将它们包围起来。它们将在代码覆盖率报告中被忽略。
编辑:我发现Xdebug经常认为右大括号是可执行的。 :( 如果发生这种情况,请将结束标记移到其下方。
If you are trying to achieve 100% code coverage but have one or more lines that you cannot test, you can surround them with special annotations. They will be ignored in the code coverage report.
Edit: I have found that Xdebug often considers the closing brace to be executable. :( If that happens, move the end tag below it.
首先确保您拥有最新和最好的 phpunit,否则代码忽略可能会丢失。接下来创建一个 phpunit.xml 文件,如下所示:
First make sure you have the latest and greatest phpunit or else the code ignore might be missing. Next create a
phpunit.xml
file that looks something like this:PHP 单元 9.6,
如果您只想忽略一行:
PHP unit 9.6,
If you want to ignore only one line :