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;) )