聚合来自PHPUnit的多个执行的代码覆盖
发布时间:2020-12-14 00:52:00 所属栏目:百科 来源:网络整理
导读:我一直在使用PHPUnit一段时间了,它开始看起来像我可能需要将我的测试分解为可以作为phpunit的单独执行运行的组。这样做的主要原因是我的大多数测试都需要在不同的进程中运行,而有些实际上不能在单独的进程中运行,因为 here记录了一个问题。我想要做的是编
我一直在使用PHPUnit一段时间了,它开始看起来像我可能需要将我的测试分解为可以作为phpunit的单独执行运行的组。这样做的主要原因是我的大多数测试都需要在不同的进程中运行,而有些实际上不能在单独的进程中运行,因为
here记录了一个问题。我想要做的是编写一个bash脚本来触发几个执行phpunit,每个配置为使用不同的设置运行不同的测试。
所以我的问题是:有没有办法聚合多个phpunit执行的代码覆盖率结果?我可以直接通过PHPUnit本身或使用其他工具吗?是否有可能使用PHPUnit的测试套件概念从一个phpunit运行中获取我正在寻找的东西?
使用PHPUnit的“–coverage-php”选项让它将coverage数据编写为序列化的PHP_CodeCoverage对象,然后使用PHP_CodeCoverage :: merge将它们组合起来,如下所示:
<?php /** * Deserializes PHP_CodeCoverage objects from the files passed on the command line,* combines them into a single coverage object and creates an HTML report of the * combined coverage. */ if ($argc <= 2) { die("Usage: php generate-coverage-report.php cov-file1 cov-file2 ..."); } // Init the Composer autoloader require realpath(dirname(__FILE__)) . '/../vendor/autoload.php'; foreach (array_slice($argv,1) as $filename) { // See PHP_CodeCoverage_Report_PHP::process // @var PHP_CodeCoverage $cov = unserialize(file_get_contents($filename)); if (isset($codeCoverage)) { $codeCoverage->filter()->addFilesToWhitelist($cov->filter()->getWhitelist()); $codeCoverage->merge($cov); } else { $codeCoverage = $cov; } } print "nGenerating code coverage report in HTML format ..."; // Based on PHPUnit_TextUI_TestRunner::doRun $writer = new PHP_CodeCoverage_Report_HTML( 'UTF-8',false,// 'reportHighlight' 35,// 'reportLowUpperBound' 70,// 'reportHighLowerBound' sprintf( ' and <a href="http://phpunit.de/">PHPUnit %s</a>',PHPUnit_Runner_Version::id() ) ); $writer->process($codeCoverage,'coverage'); print " donen"; print "See coverage/index.htmln"; 您也可以使用名为phpcov的工具合并文件,如下所述:https://github.com/sebastianbergmann/phpunit/pull/685 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |