PHPUnit: A second look

PHPUnit

Somewhere in 2007 I had a deep dive into PHPUnit, and there were a couple of things that bugged me.

Looking into it again, it turns out that since then everything has been fixed, making it perfect for integrating it into sabredav. Most of the protocol-level WebDAV stuff is all tested with litmus, but having good unit tests will help ensuring a high quality of the inner business logic. Already it has identified 2 spelling mistakes :).

My highlights:

  • No need to write 'TestSuites' anymore.
  • A 'bootstrap' setting. This file contains all the application specific logic to setup the test.
  • The Code coverage analysis is perfected.
  • The ability to specify which directories to include in the code coverage.
  • As a bonus, all these settings can be specified through a single XML configuration file. This way I can simply tell users to run 'phpunit --configuration=config.xml' and they're off..

PHPUnit3 : first impressions

PHPUnit

I finally started writing unittests with my code.. That should get rid after yet another bad habbit.. I started using versioning and writing docblocks a few years ago, but shamefully I never really did proper testing.

For a testing framework I picked PHPUnit. My main reason for picking this was that its fully written in PHP5, it can produce some pretty good reports and the biggest reason is simply because I hear a lot of good stuff about it.

PHPUnit3 is well documented, which is helpful. I have to say that I did have a some trouble getting started. Even though its stated clear in the manual, I just sort of had to figure out where to put the files, how big the scope of one unit test is and when to write a separate testing suite..

So my solution was to actually look at the Zend Framework, and watch how they did it, which was really helpful..

One thing seemed a bit weird to me.. You use the ->addTestSuite method when you add a unittest.. and you use the ->addTest when your adding a whole suit of tests.. Seems a little reversed.

The other thing was that its actually quite some effort to add suits of tests.. Every single suit needs to have a fairly complex class that needs to be repeated every time. I'm thinking of writing this with a simple xml configuration file that includes unit tests, suits and can include other xml files. It should probably also be able to add tests based on wildcards.

But overall, a great testing framework. Especially the code coverage report rocks (albeit a big buggy;) )

 1

About

My name is Evert, and I've been writing semi-regularly on this blog since 2006.

I'm currently available for contract work.

more info.

Subscribe

Dropbox

Dropbox is a simple cross-platform online backup and sync application. The first 2GB of space is free, and both you and me get an extra 250MB extra space if you sign up through this link.