我希望确定我的每个测试套件分别覆盖哪些文件。我在 PHP 8.1 项目上使用 PHPUnit 10.5 和 xDebug 进行代码覆盖。
这是我的
phpunit.xml
配置文件的样子:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap.php" colors="true"
cacheResult="false" stopOnDefect="false"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache" backupGlobals="true">
<testsuites>
<testsuite name="example">
<file>./ExampleTest.php</file>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../src</directory>
</include>
</source>>
<coverage>
<report>
<html outputDirectory="html-coverage"/>
</report>
</coverage>
</phpunit>
我做了一些研究,但没有发现任何有用的东西。有办法实现吗?
是否认为为单个测试套件寻求代码覆盖率是一种不好的做法,这就是为什么没有人尝试这样做?
任何建议或见解将不胜感激。谢谢!
您可以通过添加
coverage
标签来指定特定路径,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap.php" colors="true"
cacheResult="false" stopOnDefect="false"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache" backupGlobals="true">
<testsuites>
<testsuite name="example">
<file>./ExampleTest.php</file>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../src</directory>
</include>
</source>>
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">./path-to-directory</directory> // update this path
</include>
<report>
<html outputDirectory="html-coverage"/>
</report>
</coverage>
</phpunit>