您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit参数testsuite的使用
发布时间:2021-09-20 18:20:46编辑:雪饮阅读()
Phpunit中testsuite可以建立一个测试集合,就是包含多个tests的测试,需要给它提供一个这个测试集合所在目录,然后它将会按照这个目录来遍历取出该目录中每个php(都是继承自PHPUnit\Framework\TestCase的测试类)提出tests形成的集合。
然后还需要为这个集合配置testsuite名称,这个名称又正好对应如src目录中同名称的php文件。
那么接下来在命令行中可以通过—testsuite指定一个上面配置的这个testsuite名称即可对上面这个testsuite名称所指定的集合进行测试。
那么这里还是和之前的组织测试结构一样:
C:\Users\Administrator>tree C:\Users\Administrator\PhpstormProjects\untitled\organizing /f
卷 Acer 的文件夹 PATH 列表
卷序列号为 00000015 6A10:93B9
C:\USERS\ADMINISTRATOR\PHPSTORMPROJECTS\UNTITLED\ORGANIZING
│ phpunit.xml
│
├─src
│ autoload.php
│ Database.php
│ User.php
│
└─tests
DatabaseTest.php
UserTest.php
然后phpunit.xml中配置如:
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="database">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
<testsuites>
<testsuite name="database">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
这里配置的database正好对应src/Database.php
这里配置的tests正好对应这里的tests目录。
这里大概意思可以理解为tests目录中我们都是用来对src/Database.php这个类进行测试的所有测试方法。
虽然之前规划的仅仅只是tests/DatabaseTest.php才是对src/Database.php这个类进行测试的所有测试方法。且仅这一个tests/DatabaseTest.php,但是这里为了方便,就暂时先这样认为。
那么接下来命令行中运行时候就可以直接指定testsuite的名称进行调用测试集合了
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar --configuration C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml --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)
关键字词:phpunit,testsuite