由于您最有可能使用$this-> assert …()调用断言,您可以在测试用例中覆盖这些方法.快速示例:
class YourTestCase extends PHPUnit_Framework_TestCase { ... static private $messages = array(); ... static public function assertSame($var1,$var2,$message = '') { parent::assertSame($var1,$message); // assertSame() throws an exception if not true,so the following // won't occur unless the messages actually are the same $success = print_r($var1,true) . ' is the same as ' . print_r($var2,true); self::$messages = array_merge(self::$messages,array($success)); } static public function tearDownAfterClass() { echo implode("\n",self::$messages); } }
当然,tearDownAfterClass()可能不足以适应你的喜好.这与断言失败是不一样的.