使用PHPUnit进行单元测试并生成代码覆盖率报告的(4)
理解测试执行的模式还是很有帮助的,其他高级特性请浏览官方文档。
使用phpunit.xml编排测试套件
使用测试套件来管理测试,vi phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<!--可以定义多个 suffix 用于指定待执行的测试类文件后缀-->
<testsuite name="Tests">
<directory suffix="Test.php">./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<!--可以定义多个 对./app下的业务代码做覆盖率统计-->
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<logging>
<!--覆盖率报告生成类型和输出目录 lowUpperBound低覆盖率阈值 highLowerBound高覆盖率阈值-->
<log type="coverage-html" target="./reports" lowUpperBound="35" highLowerBound="70"/>
</logging>
</phpunit>
然后直接运phpunit行即可:
[root@localhost unit]# phpunit PHPUnit 6.5.14 by Sebastian Bergmann and contributors. Time: 81 ms, Memory: 4.00MB No tests executed! Generating code coverage report in HTML format ... done
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持黑区网络。
