Re: Unit test standard
| From: | Greg Beaver | Date: | Sun, 06 Jun 2004 18:18:45 +0000 |
| Subject: | Re: Unit test standard | ||
| References: | 1 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-1393@lists.php.net to get a copy of this message | ||
Jackson Miller wrote:
Is there a PEAR coding standard for unit tests? I don't see it mentioned anywhere in the coding standards section of pear.php.net. Also, is there a recommended (general or PEAR specific) way to write unit tests for classes that connect to a database and run queries? Thanks, -JacksonHi Jackson, There is no standard. Any package that interacts with the outside world probably should provide tests that can work with a real outside situation, or with mock objects that simulate the outside world. In this way, users can verify with both real-world and with expected real world. In other words, you want to test that the code responds correctly to expected input (both valid and invalid), and then you should have separate tests that make sure the input you're getting from the database matches the expected input. Please forgive me if this is old news to you - I do not mean to be patronizing. Here's a rundown of the advantages/disadvantages of the three big options: Simpletest has a nice mock object implementation, but is not in PEAR phpt (run-tests.php from PHP's cvs in php-src) can handle crashes in PHP, but requires re-inventing the wheel for every test (no helper methods exist like the assert*() methods) PHPUnit is in PEAR, but not as powerful as Simpletest. Unit testing is relatively new in PEAR - most packages don't have any. We're still trying to get people to document their code, so it's kind of a baby steps situation :). If you discover any neat tricks or have difficulties in unit testing, you should definitely post them. Greg