is there a way to print the execution time of each test with PHPUnit?
To add some more ways:
You can write a custom Test listener and add it to the XML file. In that listener you can access the $testResult->time()
. Some lines in your phpunit.xml and a 10 line PHP class. Not too much hassle.
class SimpleTestListener implements PHPUnit_Framework_TestListener
{
public function endTest(PHPUnit_Framework_Test $test, $time)
{
printf("Test '%s' ended and took %s seconds.\n",
$test->getName(),
$test->time()
);
}
}
If you generate a junit.xml anyways (for CI or while creating code coverage) all the numbers are there anyways and with a simple XSLT you can make those even more readable.
Example junit.xml
DemoTest::testFail
Failed asserting that <boolean:false> is true.
/home/edo/foo.php:9
and with an transformation like this:
Tests
-
:
Failed !
you get lines showing you:
(the HTML is just an example, it should be easily adaptable).
Referencing my own blog post here: http://edorian.github.io/2011-01-19-creating-your-custom-phpunit-output.formats/ for the xslt stuff.