One of the benefits of using an even moderately mature piece of open-source software is that it usually has a good bit of sugar—or ease-of-use features—in it. As more developers use it, convenience functions are added to suit developers' individual styles, and this often produces a rich array of syntaxes and features.
Creating More Informative Error Messages Sometimes you would like a more informative message than this: PHPUnit 1.0.0-dev by Sebastian Bergmann. .F. Time: 0.00583696365356 There was 1 failure: 1) TestCase emailaddresstestcase->testlocalpart() Especially when a test is repeated multiple times for different data, a more informative error message is essential to understanding where the break occurred and what it means. To make creating more informative error messages easy, all the assert functions that TestCase inherit from PHPUnit::Assert support free-form error messages. Instead of using this code: function testLocalPart() {
$email = new EmailAddress("georg@omniti.com");
// check that the local part of the address is
which generates the aforementioned particularly cryptic message, you can use a custom message: function testLocalPart() {
$email = new EmailAddress("georg@omniti.com");
// check that the local part of the address is
This produces the following much clearer error message: PHPUnit 1.0.0-dev by Sebastian Bergmann. .F. Time: 0.00466096401215 There was 1 failure: 1) TestCase emailaddresstestcase->testlocalpart() Hopefully, by making the error message clearer, we can fix the typo in the test.
blog comments powered by Disqus |