您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-defaultTestSuite
发布时间:2021-10-17 19:32:58编辑:雪饮阅读()
defaultTestSuite 属性
此属性配置默认测试套件名称。
这里以之前的组织测试为例。
首先在src目录中建立两个php文件做为两个套件基境(可以假定理解为mock原始对象):
[root@localhost organizing]# cat /usr/local/organizing/src/demo.php /usr/local/organizing/src/demo2.php
<?php
?><?php
?>
没错,这两个文件我给的内容都空的php脚本。
然后建立两个用于测试的测试用例并分别放置于两个目录:
[root@localhost organizing]# cat /usr/local/organizing/tests/MyTest.php /usr/local/organizing/tests2/My2Test.php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(true);
}
public function testThree(): void
{
$this->assertTrue(true);
}
}<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class My2Test extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(true);
}
}
这两个测试用例类第一个类中有3个测试,第二个类中有2个测试。
那么接下来需要在配置文件中配置testSuite站点列表了:
phpunit.xml:
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="demo">
<directory>tests</directory>
</testsuite>
<testsuite name="demo2">
<directory>tests2</directory>
</testsuite>
</testsuites>
</phpunit>
这里的demo和demo2正对应原src中的demo.php和demo2.php
那么接下来我们运行如下命令:
[root@localhost organizing]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar -c /usr/local/organizing/phpunit.xml
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
... 3 / 3 (100%)
Time: 00:00, Memory: 18.00 MB
OK (3 tests, 3 assertions)
可以看到这里只指定了phpunit.xml而并没有指定要运行的testSuite,那么从结果上看到有3个测试,则可以断定用的是testSuite站点列表中的第一个也即就是demo对应的tests目录中的测试用例类。
那么接下来我们修改phpunit.xml如:
<phpunit bootstrap="src/autoload.php" defaultTestSuite="demo2">
<testsuites>
<testsuite name="demo">
<directory>tests</directory>
</testsuite>
<testsuite name="demo2">
<directory>tests2</directory>
</testsuite>
</testsuites>
</phpunit>
也就是修改了默认测试套件defaultTestSuite指定为demo2这个测试套件,那么接下来再次运行上面的命令行命令如:
[root@localhost organizing]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar -c /usr/local/organizing/phpunit.xml
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
.. 2 / 2 (100%)
Time: 00:00, Memory: 18.00 MB
OK (2 tests, 2 assertions)
那么这里可以看到只有两个测试,正好对应demo2测试套件对应的tests2目录中的My2Test测试用例类中的测试方法个数了。
关键字词:phpunit,defaultTestSuite
相关文章
- phpunit-phpunit.xml-phpunit-testSuiteLoaderClass与
- phpunit-phpunit.xml-phpunit-timeoutForLargeTests
- phpunit-phpunit.xml-phpunit-timeoutForMediumTests
- phpunit-phpunit.xml-phpunit-timeoutForSmallTests
- phpunit-phpunit.xml-phpunit的enforceTimeLimit与def
- phpunit-phpunit.xml-phpunit-beStrictAboutTodoAnnot
- phpunit-phpunit.xml-beStrictAboutTestsThatDoNotTes
- phpunit-phpunit.xml-phpunit-beStrictAboutOutputDur
- phpunit-phpunit.xml-phpunit-stopOnDefect
- phpunit-phpunit.xml-stopOnSkipped