For Programmers: Free Programming Magazines  


Home > Archive > PHP PEAR Questions and Answers > June 2004 > Unit test standard









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Unit test standard
Jackson Miller

2004-06-06, 3:56 pm

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,
-Jackson
Greg Beaver

2004-06-06, 3:56 pm

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,
> -Jackson


Hi 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/divantages 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com