PHPUnit --coverage-html无效

问题描述 投票:0回答:1

我使用PHP 7.0并使用PHPunit执行测试用例。那些工作正常。但是当尝试使用PHPUnit 6.3.0或5.7.23使用--coverage-html选项运行PHPUnit时,它只显示可用选项而不是生成代码覆盖率报告。

我没有使用任何phpunit.xml文件,是强制性的,如果是,那么如何把我的目录。我的项目中有两个文件夹 - 一个用于lib(核心php类文件),另一个用于具有单元测试用例的测试。

php phpunit code-coverage php-7
1个回答
0
投票

假设您的代码在标准目录中(例如src代码和tests用于测试),请使用以下phpuni.xml.dist文件

<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
    backupGlobals="false"
    colors="true"
    bootstrap="vendor/autoload.php"
>
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
        </whitelist>
    </filter>
</phpunit>

然后你可以运行phpunit来获得没有覆盖的测试和phpunit coverage-html build来获得覆盖测试(随意用你喜欢的任何目录名替换build

© www.soinside.com 2019 - 2024. All rights reserved.