I've split my tests into different groups so that I don't bother running the slowest ones until absolutely necessary.
However, some are still slow.
So I'd love to see the names of tests that either failed or had errors even before the whole suite of tests finishes running.
E.g. currently when I run phpunit tests/Unit/ --verbose
, I see output like this:
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.....
But even though I see the "F", I need to wait a long time before I see which test it was that failed.
I'd love to be able to allow the tests to continue running but simultaneously start looking into that particular test to see why it failed.
How?
You have at least 3 options:
add --debug flag (after reading your comments it seems this won't do what you need which is show in real time what test failed)
create a printer class and use it with --printer flag
add --testdox flag
A long time ago I had to do my own printer because I needed to display how long a test took. So basically I was printing when a test started, its name and how long it took. You can use this code and adapt it to your needs.
You need to create a new class (usually under /tests directoy). Make sure this class Extends PHPUnit_TextUI_ResultPrinter. Then in your phpunit.xml file you add these settings inside
printerFile="tests/TestDurationPrinter.php" <-- filename
printerClass="TestDurationPrinter <-- Class you created.
My Printer looks like this:
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) )); } }
In your case, I think using --testdox would be enough. If it doesn't work, then I'd recommend creating your own printer, bear in mind that you still need to get access to the test result (which I don't know how to do it) so you would need to google that.
I hope this helps you.
Edit: another thing you can do is to add the flag
--stop-on-errorso that tests stop as soon as there's an error. There's also
--stop-on-failure(I think this is want you want). I always use both as my testsuite has around 800 tests and the entire execution takes around 3 minutes.