您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-stopOnFailure
发布时间:2021-10-13 22:32:40编辑:雪饮阅读()
stopOnFailure是干嘛的?这里说的stopOnFailure是配置于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
{
$this->assertTrue(false);
}
public function testTwo(): void
{
$this->assertTrue(false);
}
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-stopOnFailure\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
FF. 3 / 3 (100%)
Time: 00:00.003, Memory: 20.00 MB
There were 2 failures:
1) MyTest::testOne
Failed asserting that false is true.
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\MyTest.php:9
2) MyTest::testTwo
Failed asserting that false is true.
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\MyTest.php:13
FAILURES!
Tests: 3, Assertions: 3, Failures: 2.
这里可以看到有断言失败,那么并没有阻止下一个测试方法的运行,只是说明了下某个断言失败。这是默认情况下的运行结果,那么默认情况下stopOnFailure配置为false。
那么如果stopOnFailure配置为true呢?
phpunit.xml:
<phpunit stopOnFailure="true">
</phpunit>
其之运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
F
Time: 00:00.003, Memory: 20.00 MB
There was 1 failure:
1) MyTest::testOne
Failed asserting that false is true.
D:\phpstudy_pro\WWW\phpunitLearning\phpunitLearning-stopOnFailure\MyTest.php:9
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
可以看到此时它就遇到一个断言错误,那么就那个子就那个停止了接下来的测试方法的执行,这就是stopOnFailure为true的作用。
关键字词: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
- phpunit-phpunit.xml-phpunit-columns
- phpunit-phpunit.xml-phpunit-backupStaticAttributes