您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-beStrictAboutTestsThatDoNotTestAnything
发布时间:2021-10-16 22:29:33编辑:雪饮阅读()
beStrictAboutTestsThatDoNotTestAnything 属性
可能值:true 或 false(默认值:true)
此属性配置在测试未执行任何断言(预期也算在内)时,PHPUnit 是否应将其标记为有风险(risky)。
可以看看如下程序:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
public function testOne(): void
{
}
public function testTwo(): void
{
}
public function testThree(): void
{
$this->assertTrue(true);
}
}
该程序中有两个没有任何断言的程序。
其执行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\phpunit-9.5.10.phar D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
RR. 3 / 3 (100%)
Time: 00:00.289, 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-beStrictAboutTestsThatDoNotTestAnything\MyTest.php:5
2) MyTest::testTwo
This test did not perform any assertions
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\MyTest.php:9
OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 1, Risky: 2.
可见默认测试结果有两个风险测试。
那么这是默认配置beStrictAboutTestsThatDoNotTestAnything为true的作用。那么假如phpunit.xml:
<phpunit beStrictAboutTestsThatDoNotTestAnything="false">
</phpunit>
那么其运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutTestsThatDoNotTestAnything\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
... 3 / 3 (100%)
Time: 00:00.002, Memory: 18.00 MB
OK (3 tests, 1 assertion)
其之结果可见beStrictAboutTestsThatDoNotTestAnything设定为false后将不会再次对测试方法中没有任何断言,而标记为risky风险了
关键字词:phpunit,beStrictAboutTestsThatDoNotTestAnything
上一篇:phpunit-phpunit.xml-phpunit-beStrictAboutOutputDuringTests
下一篇:phpunit-phpunit.xml-phpunit-beStrictAboutTodoAnnotatedTests
相关文章
- phpunit-phpunit.xml-phpunit-beStrictAboutOutputDur
- phpunit-phpunit.xml-phpunit-stopOnDefect
- phpunit-phpunit.xml-stopOnSkipped
- phpunit-phpunit.xml-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