JApacheCon
13 Dec 2005I'm at JApacheCon (ApacheCon that has been infested with Java) this week in sunny San Diego. On Sunday, Geoff Young and I gave our tutorial, Power PHP Testing, which went really well. Most of the attendees had PHP experience and no testing experience, so it was a perfect fit.
We covered testing theory as well as some practical examples using phpt, Simple-Test, PHPUnit, and (of course) Apache-Test. We have tarballs for each framework that provide everything you need (I'll link to these in another post), including a Makefile so that make test runs your test suite.
The challenge with being the authors of one of the testing frameworks is that we are obviously biased. (This is stated in the abstract.) Our approach was to try to make every testing framework shine as much as possible, because the purpose of the talk is to encourage testing in the PHP community, regardless of which tool is used. I'll probably elaborate later, but here are some of the things we did for each framework:
- Simple-Test - Because the default reporter (reporter.php) is an HTML reporter, automated testing is difficult. (You'd have to write your own HTTP client to aggregate the results.) Luckily, Mike Lively has created a TAP reporter (tap-reporter.php), so we used this in our demonstration (and tarball).
- PHPUnit - PHPUnit has a number of dependencies (which is less of a problem if you already have a fairly complete PEAR installation), so we bundled everything you need. We also wrote our own phpunit tool to run the tests (this is executed when you type make test), and it modifies include_path to resolve the inconsistent ways that dependencies are included.
- phpt - Executing phpt tests is actually very straightforward, so all we did was add the test target to the Makefile to execute the proper command. We did add an assertNoUnwantedPuke target to our Makefile to clean up the mess that is created whenever tests fail.
- Apache-Test - Because Apache-Test already supports automated testing with make test, no changes were necessary. However, we did create a tarball to demonstrate using Simple-Test (instead of test-more.php) within the Apache-Test framework.
The biggest difference between the various frameworks is how failures are handled, and this is where Apache-Test shines. With some enhancements to the TAP reporter for Simple-Test, however, I think it can be just as good. I'll probably blog about this separately after speaking with the authors of the other frameworks, because I want to make sure that we're highlighting the advantages and disadvantages of each framework fairly.
The conference has been great for the hallway conversations and the opportunity to meet and work with other speakers and attendees, but the interesting sessions are few and far between. Andrei Zmievski's recent comment, "2:00 is the next real session," sums this up nicely.