在之前配置phpunit的testsuite时候使用的是目录的方式配置的:
像是phpunit.xml:
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="database">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
那么其实还有一种配置testsuite模式就是file模式,file模式可以更加精细的选择测试集中测试方法来源于某几个指定的测试类文件,那么phpunit.xml如:
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="database">
<file>tests/DatabaseTest.php</file>
<file>tests/UserTest.php</file>
</testsuite>
</testsuites>
</phpunit>
这样运行结果和前面用目录的方式一样,还是有4个tests
C:\Users\Administrator\PhpstormProjects\untitled\organizing>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar --testsuite database
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
.... 4 / 4 (100%)
Time: 00:00.006, Memory: 20.00 MB
OK (4 tests, 5 assertions)
那么这里我就可以随便调整,比如我不要来源于tests/UserTest.php中的测试,则:
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="database">
<file>tests/DatabaseTest.php</file>
</testsuite>
</testsuites>
</phpunit>
那么再次运行:
C:\Users\Administrator\PhpstormProjects\untitled\organizing>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar --testsuite database
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 00:00.004, Memory: 20.00 MB
OK (1 test, 1 assertion)
这样就只有1个测试了。这里tests/DatabaseTest.php中也就是只有一个测试方法。