您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-beStrictAboutOutputDuringTests
发布时间:2021-10-16 22:10:17编辑:雪饮阅读()
beStrictAboutOutputDuringTests属性是配置于phpunit配置文件的phpunit元素上的属性。
beStrictAboutOutputDuringTests 属性
可能值:true 或 false(默认值:false)
此属性配置当被测代码(或测试代码)打印输出时,PHPUnit 是否应将测试标记为有风险(risky)。
可以看看如下程序:
MyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
public function testOne(): void
{
var_dump(1);
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(true);
}
public function testThree(): void
{
$this->assertTrue(true);
}
}
那么假定phpunit.xml配置如:
phpunit.xml:
<phpunit beStrictAboutOutputDuringTests ="true">
</phpunit>
但是我不加载该phpunit.xml而是直接执行phpunit去测试上面的程序:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\phpunit-9.5.10.phar D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
.D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\MyTest.php:7:
int(1)
.. 3 / 3 (100%)
Time: 00:00.035, Memory: 20.00 MB
OK (3 tests, 3 assertions)
可见是有输出的,但是并没有报出risky有风险的标记。
那么假如加载了该phpunit.xml:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
RD:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\MyTest.php:7:
int(1)
.. 3 / 3 (100%)
Time: 00:00.003, Memory: 20.00 MB
There was 1 risky test:
1) MyTest::testOne
This test printed output: D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-beStrictAboutOutputDuringTests\MyTest.php:7:
int(1)
OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 3, Risky: 1.
可以看到beStrictAboutOutputDuringTests为true时使得测试方法中有输出的时候被视为risky有风险的测试。
关键字词:phpunit,beStrictAboutOutputDuringTests
上一篇:phpunit-phpunit.xml-phpunit-stopOnDefect
下一篇:phpunit-phpunit.xml-beStrictAboutTestsThatDoNotTestAnything
相关文章
- 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
- phpunit-phpunit.xml-phpunit-convertWarningsToExcep