We do the same in our selenium tests. You need to catch the exceptions caused by assertion errors, and the only way to do this is to create your own test case base class that overrides the assertion methods. You can save fault messages and end the test at the end with a test listener.
I don't have the code in front of me, but it was pretty straight forward. For instance,
abstract class DelayedFailureSeleniumTestCase extends PHPUnit_Extension_SeleniumTestCase { public function assertElementText($element, $text) { try { parent::assertElementText($element, $text); } catch (PHPUnit_Framework_AssertionFailedException $e) { FailureTrackerListener::addAssertionFailure($e->getMessage()); } } ... other assertion functions ... } class FailureTrackerListener implements PHPUnit_Framework_TestListener { private static $messages; public function startTest() { self::$messages = array(); } public static function addAssertionFailure($message) { self::$messages[] = $message; } public function endTest() { if (self::$messages) { throw new PHPUnit_Framework_AssertionFailedException( implode("\n", self::$messages)); } } }
source share