简体   繁体   English

如何在Windows上获得Netbeans PHPUnit代码覆盖率?

[英]How to get Netbeans PHPUnit code coverage working on Windows?

I am trying to get Netbeans code coverage checking feature working. 我正在尝试使Netbeans 代码覆盖率检查功能正常工作。 I am working with PHP on a Windows XAMPP setup, and have setup PHPUnit which seems to work fine for running unit tests. 我正在Windows XAMPP安装程序上使用PHP,并且已经安装了PHPUnit,它似乎可以很好地运行单元测试。

When I right-click my project and select "Code Coverage > Collect and Display Code Coverage", it displays a little bar at the bottom that says "0%" and has options to run tests and get a report. 当我右键单击项目并选择“代码覆盖率>收集并显示代码覆盖率”时,它将在底部显示一个小条,显示为“ 0%”,并具有运行测试和获取报告的选项。

I run the tests and check the report, yet it remains at 0%. 我运行测试并检查了报告,但它仍为0%。 If I check the report it says "No data - have you run your code yet?" 如果我查看该报告,它会显示“没有数据-您是否正在运行代码?” I've tried rerunning the tests but it still does this. 我尝试过重新运行测试,但仍然可以执行此操作。 I've also tried just running the project, and also "debugging" the project to no avail. 我也尝试过仅运行项目,并且“调试”项目也无济于事。

Recent information on the topic is hard to come by, but judging by the PHPUnit documentation there could be an issue with Xdebug (I've enabled it, but no idea if it is working properly as I've not used it from within Netbeans before). 很难获得有关该主题的最新信息,但是根据PHPUnit文档判断,Xdebug可能存在问题 (我已启用它,但由于它以前没有在Netbeans中使用过,所以不知道它是否工作正常) )。 Some old sources say that there are two php.ini's in Xampp (one for web, one for CLI), but I can't find a second one (guessing this has since changed). 一些老消息来源说Xampp中有两个php.ini(一个用于Web,一个用于CLI),但是我找不到第二个(猜测此后已经改变)。

I'm sure I am probably missing something fairly basic like an Xdebug setting or something... any help? 我确定我可能会缺少一些基本的东西,例如Xdebug设置或其他任何帮助?

Here's the XDebug section from my php/php.ini file: 这是我的php / php.ini文件中的XDebug部分:

[XDebug]
zend_extension = "D:\xampp\php\ext\php_xdebug.dll"
;xdebug.profiler_append = 0
;xdebug.profiler_enable = 1
;xdebug.profiler_enable_trigger = 0
;xdebug.profiler_output_dir = "\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
;xdebug.trace_output_dir = "\xampp\tmp"

Is probably caused by this: http://forums.netbeans.org/topic47374.html . 可能是由于以下原因引起的: http : //forums.netbeans.org/topic47374.html Apparently PHPUnit cannot deal with starting on c:\\ and testing something on D:. 显然,PHPUnit无法处理从c:\\开始并在D:上进行测试。

Therefore I run any tests I want coverage-reports on from the commandline using the --coverage-html /path/to/directory argument: 因此,我使用--coverage-html / path / to / directory参数从命令行运行了我希望覆盖率报告的所有测试:

phpunit --bootstrap bootstrap.php --configuration phpunit.xml --coverage-html ./report ./unit

Where the last argument (./unit) means that this will test als tests in the unit/ subdirectory. 最后一个参数(./unit)表示这将测试unit /子目录中的als测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM