如何多次运行php单元并连接覆盖率报告? [英] how to run php unit multiple times and concatenate the coverage report?

查看:66
本文介绍了如何多次运行php单元并连接覆盖率报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试过的代码充满了最终的静态类.尽管我们无法对其进行重构以进行更好的测试,但我有一个中间解决方案,可以在其自己的流程中运行多个小测试.一切正常.但是我没有覆盖报告,因为一个覆盖另一个.

My tested code is full of final static classes. and while we can't refactor it for better tests, i have a intermediate solution that runs several small tests on it's own process. and all works fine. but i get no coverage report as one overwrite the other.

我目前正在用三叶草生成报告,但是我非常愿意接受其他报告.

I'm currently generating the report in clover, but i am very open to other reports.

我的测试仅在phpunit以以下方式运行时有效:

my tests only work when phpunit is run as:

/home/y/bin/phpunit --coverage-html clover --coverage-clover clover/report.xml --include-path src/  tests/aTest.php
OK (1 test, 1 assertions)
/home/y/bin/phpunit --coverage-html clover --coverage-clover clover/report.xml --include-path src/  tests/bTest.php
OK (1 test, 1 assertions)
/home/y/bin/phpunit --coverage-html clover --coverage-clover clover/report.xml --include-path src/  tests/cTest.php
OK (1 test, 1 assertions)

但是,这将导致每次运行都要清除前一个报告.所以我只得到最后一份报告.而且,如果我尝试按照phpunit期望生成完整报告的方式运行它们,那么我会失败,因为我所有的类都包含自己的静态类.

But that will result in each run wipping the report from the previous. So i only get a report for the last one. And if i try to run them as phpunit expects to generate the full report, i have the failure because all my classes include their own static ones.

/home/y/bin/phpunit --coverage-html clover --coverage-clover clover/report.xml --include-path src/  tests/
. (first test pass)
PHP Fatal error:  Cannot redeclare class Something
make[1]: *** [phpunit_run] Error 255

(但是即使使用--process-isolation --no-globals-backup,上述操作也会失败,因为它们的含义不完全是...)-这不是关于如何在php单元上正确进行进程隔离的另一个问题.我几次运行都很好,我只想要一份完整的覆盖率报告:)

(but the above will fail even with --process-isolation --no-globals-backup because are not exactly what they mean...) -- This is NOT yet another question on how to get properly process isolation on php unit. i'm fine running it several times, i just want a full coverage report :)

是否可以像第一个代码块那样使测试正确运行(即在多个进程上避免污染全局类声明空间),但是仍然具有全面的代码覆盖率报告?

Is there any way to get the tests to run correctly (i.e. on several process to avoid tainted global class declaration space) like the first code block, but still have comprehensive code coverage report?

谢谢!

推荐答案

Schleis的答案对我不起作用.在我的情况下,unserialize()方法引发错误:偏移量错误...

Schleis answer did not work for me. The unserialize() method throws an error in my case: Error at offset...

不过,有一种非常简单的方法可以实现这一目标:

However there is a very easy way to achieve this:

此处所述下载phpcov.

Download phpcov as described here.

已使phpunit生成具有以下内容的php覆盖率报告:

Have phpunit generate php coverage reports with:

phpunit --coverage-php coverage/cov/foo.cov tests/foo
phpunit --coverage-php coverage/cov/bar.cov tests/bar

现在您有2个.cov文件.然后在您最喜欢的外壳中:

Now you have 2 .cov files. Then in your favourite shell:

phpcov merge --clover clover.xml /coverage/cov

它将生成一个clover.xml报告文件.

It will generate one clover.xml report file.

这篇关于如何多次运行php单元并连接覆盖率报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆