引入依赖包
thinkphp5.0官方提供的有composer包【think-testing】,但是官方的包里面依赖的phpunit版本太低,无法在php7.0以上正常使用,phpunit需要升级到6.0版本,使用新的包【composer require 0377/think-test-new】0377/think-test-new
composer require 0377/think-test-new
根目录会生成tests目录
使用下面的命令执行测试用例
php think unit
根目录phpunit.xml配置
相比官方配置,增加了whitelist里面的extend,增加了生成测试覆盖率报告logging【不需要可以删除或注释掉】
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="./tests/codeCoverage" charset="UTF-8"/>
</logging>
<filter>
<whitelist>
<directory suffix=".php">application/</directory>
<directory suffix=".php">extend/</directory>
</whitelist>
</filter>
</phpunit>