您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-stopOnRisky
发布时间:2021-10-14 23:04:50编辑:雪饮阅读()
stopOnRisky是干什么用的呢?这里所谓的stopOnRisky是指在phpunit的phpunit.xml的phpunit的属性。
此属性默认是false,无论在phpunit的phpunit.xml的phpunit的属性是否配置。
对于如下程序:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\ResultPrinter;
use PHPUnit\TextUI\DefaultResultPrinter;
final class MyTest extends TestCase
{
public function testOne(): void
{
}
public function testTwo(): void
{
}
public function testThree(): void
{
$this->assertTrue(true);
}
}
默认情况下的phpunit.xml:
<phpunit>
</phpunit>
那么该测试程序运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
RR. 3 / 3 (100%)
Time: 00:00.031, Memory: 20.00 MB
There were 2 risky tests:
1) MyTest::testOne
This test did not perform any assertions
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\MyTest.php:7
2) MyTest::testTwo
This test did not perform any assertions
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\MyTest.php:11
OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 1, Risky: 2.
是会被视为有风险的,对于这里的空的测试方法来说,这里进行了3个测试,断言了一次,出现了2个风险测试。
stopOnRisky 属性
可能值:true 或 false(默认值:false)
此属性配置是否应当在第一个以“有风险(risky)”状态结束的测试之后停止测试套件的执行。
就是说上面的测试类中虽然有两个风险测试,但是测试照样执行下去不会因为有风险测试而不继续测试接下来的第二个(第二个风险测试不会因为第一个是风险测试而不执行)、第三个测试。
那么这里将stopOnRisky置为true再来看看。
phpunit.xml:
<phpunit stopOnRisky="true">
</phpunit>
那么接下来的运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
R
Time: 00:00.002, Memory: 20.00 MB
There was 1 risky test:
1) MyTest::testOne
This test did not perform any assertions
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnRisky\MyTest.php:7
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
可以看到这次是只有一个测试,0个断言,1个风险测试,这说明了遇到第一个风险测试后就不会继续执行测试类的其它测试方法了,直接中断测试了。这个就是stopOnRisky配置值为true的作用。
关键字词:phpunit,stopOnRisky
相关文章
- phpunit-phpunit.xml-phpunit-stopOnIncomplete
- phpunit-phpunit.xml-phpunit-stopOnFailure
- phpunit-phpunit.xml-phpunit-stopOnError
- phpunit-phpunit.xml-phpunit-printerClass与printerF
- phpunit-phpunit.xml-phpunit-processIsolation
- phpunit-phpunit.xml-phpunit-forceCoversAnnotation
- phpunit-phpunit.xml-phpunit-convertWarningsToExcep
- phpunit-phpunit.xml-phpunit-convertNoticesToExcept
- phpunit-phpunt.xml-phpunit-convertErrorsToExceptio
- phpunit-phpunit.xml-phpunit-convertDeprecationsToE