如何在所有测试完成之前显示失败的PHPUnit测试的名称
我把测试分成了不同的组,这样在绝对必要之前,我就不用麻烦运行最慢的测试了 然而,有些仍然缓慢 因此,我希望看到在整个测试套件运行完成之前失败或出现错误的测试的名称 例如,当前当我运行如何在所有测试完成之前显示失败的PHPUnit测试的名称,php,phpunit,Php,Phpunit,我把测试分成了不同的组,这样在绝对必要之前,我就不用麻烦运行最慢的测试了 然而,有些仍然缓慢 因此,我希望看到在整个测试套件运行完成之前失败或出现错误的测试的名称 例如,当前当我运行phpunit测试/Unit/--verbose时,我看到如下输出: PHPUnit 7.5.1 by Sebastian Bergmann and contributors. Runtime: PHP 7.2.14-1+ubuntu16.04.1+deb.sury.org+1 with Xdebug
phpunit测试/Unit/--verbose
时,我看到如下输出:
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.
Runtime: PHP 7.2.14-1+ubuntu16.04.1+deb.sury.org+1 with Xdebug 2.6.0
Configuration: /home/vagrant/Code/myproject/phpunit.xml
........F.....
class TestDurationPrinter extends \PHPUnit_TextUI_ResultPrinter
{
/**
* @param PHPUnit_Framework_Test|PHPUnit_Extensions_PhptTestCase $test
*/
public function startTest(PHPUnit_Framework_Test $test)
{
$this->write(sprintf(
"\nRunning '%s::%s'...",
get_class($test),
$test->getName()
));
}
/**
* @param PHPUnit_Framework_Test|PHPUnit_Extensions_PhptTestCase $test
* @param float $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
{
$this->write(sprintf(
"ended and took ~ %s seconds.",
round($time)
));
}
}
但是,即使我看到了“F”,我也需要等待很长时间才能看到哪个测试失败了
我希望能够允许测试继续运行,但同时开始研究特定的测试,看看它失败的原因
如何操作?您至少有3个选项:
printerFile="tests/TestDurationPrinter.php" <-- filename
printerClass="TestDurationPrinter <-- Class you created.
printerFile=“tests/TestDurationPrinter.php”我很感激,现在我终于想出了我更喜欢的东西:
1) 我编辑了phpunit.xml的
标记,以包括:
printerFile="tests/CustomPhpUnitConsolePrinter.php"
printerClass="CustomPhpUnitConsolePrinter"
2) 我的CustomPhpUnitConsolePrinter.php如下所示:
感谢您的回复,但是--debug
一点帮助都没有,而且上的文档非常稀疏。您通过--debug得到了什么输出?我也知道正在执行的测试的所有名称,但它没有以任何方式指示哪些测试失败,所以这不是很有帮助。酷。我不知道--testdox
。我希望有一个不那么冗长的版本(例如,一个对所有成功都保持沉默的版本),但现在这是一个非常好的简单选择。谢谢
--stop-on-failure
printerFile="tests/CustomPhpUnitConsolePrinter.php"
printerClass="CustomPhpUnitConsolePrinter"
<?php
class CustomPhpUnitConsolePrinter extends \PHPUnit\TextUI\ResultPrinter {
protected static $skippedTests = [];
protected static $testsWithUnknownStatus = [];
/**
* @param \PHPUnit\Framework\Test|\PHPUnit\Extensions\PhptTestCase $test
* @param float $time
*/
public function endTest(\PHPUnit\Framework\Test $test, $time): void {
parent::endTest($test, $time);
$status = $test->getStatus();
if ($status != \PHPUnit\Runner\BaseTestRunner::STATUS_PASSED) {//https://stackoverflow.com/a/6744246/470749
if ($status == \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED) {
self::$skippedTests[] = \PHPUnit\Util\Test::describeAsString($test);
} else if ($status == \PHPUnit\Runner\BaseTestRunner::STATUS_UNKNOWN) {
self::$testsWithUnknownStatus[] = \PHPUnit\Util\Test::describeAsString($test);
} else {
$this->write(\sprintf(PHP_EOL . "[%s]", \PHPUnit\Util\Test::describeAsString($test)));
}
}
}
protected function printFooter(\PHPUnit\Framework\TestResult $result): void {
if (self::$skippedTests) {
$this->write(PHP_EOL . strtoupper('► Skipped tests:') . PHP_EOL);
$this->write(implode(PHP_EOL, self::$skippedTests) . PHP_EOL);
}
if (self::$testsWithUnknownStatus) {
$this->write(PHP_EOL . strtoupper('► Tests with Unknown status:') . PHP_EOL);
$this->write(implode(PHP_EOL, self::$testsWithUnknownStatus) . PHP_EOL);
}
parent::printFooter($result);
}
}
<logging>
<!-- https://stackoverflow.com/a/52377685/470749-->
<log type="testdox-html" target="./storage/logs/testdox.html"/>
</logging>