PHPUnit Code Coverage(PHPUnit 代码覆盖率)
问题描述
我正在学习单元测试 Zend Framework 应用程序.到目前为止,我已经设置了 PHPUnit 以使用 Zend Framework 并开始编写一些简单的测试用例.
I am learning the ropes with Unit testing Zend Framework applications. So far I have set up PHPUnit to work with Zend Framework and have started writing some simple Test Cases.
我的问题是,我想知道为什么 Code Coverage 尽管在我的 phpunit.xml 的日志记录标签中设置但不起作用.
My issue is that I am wondering why Code Coverage does not work in spite of being set in the logging tag in my phpunit.xml.
我没有收到任何错误,但没有生成覆盖率报告.
I don't get any error but no coverage report is generated.
但是当我运行 phpunit --coverage <dir>
我的phpunit的日志部分如下:
The logging section of my phpunit is as below:
<phpunit bootstrap="./application/bootstrap.php" colors="true">
<testsuite name="CI Test Suite">
<directory>./</directory>
</testsuite>
<testsuite name="Library Test Suite">
<directory>./library</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../application/</directory>
<exclude>
<directory suffix=".phtml">../application</directory>
<file>../application/Bootstrap.php</file>
<file>../application/controllers/ErrorController.php</file>
</exclude>
</whitelist>
<logging>
<log type="coverage-html" target="./log/report" charset="UTF-8" yui="true"
highlight="true" lowUpperBound="50" highLowerBound="80" />
<log type="testdox" target="./log/testdox.html" />
</logging>
</filter>
</phpunit>
有人遇到过这种情况吗?那么可能的问题是什么?
Anyone encounter this before? What is then likely problem?
推荐答案
这是我的一个项目的 phpunit.xml,这很好用.如您所见,日志记录部分在过滤器部分之外,因此这可能是 Mark Baker 评论的问题.我选择了这个,因为它来自一个小项目,非常简单.
Here is the phpunit.xml for one of my projects, this works fine. As you can see, the logging section is outside the filter section, so that is probably your issue as commented by Mark Baker. I chose this one as it is from a small project and is very simple.
<phpunit bootstrap="./bootstrap.php" colors="false">
<testsuite name="HSSTests">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">d:/wamp/app_hss/</directory>
<exclude>
<directory suffix=".phtml">d:/wamp/app_hss/</directory>
<directory suffix=".php">d:/wamp/app_hss/tests/</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/codeCoverage" charset="UTF-8"
yui="true" highlight="true"
lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="./log/testdox.html" />
</logging>
</phpunit>
您可能需要的所有信息都在 PHPunit 手册中.
All the information you could ever need on this is in the PHPunit manual.
这篇关于PHPUnit 代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHPUnit 代码覆盖率
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
