Finally used PHPUnit and I like it

I have been working quite a bit lately with the cvs version PHPUnit3. I have spent alot of time in testing using SimpleTest and I have also given some time to test-more.php. However, up until just recently I had honestly never used PHPUnit before. The big motivational factor for me (other than to try something new) was to see how the code coverage feature was coming along.

I would have to say that after a few weeks of tinkering with it I am impressed. Now, keep in mind that I am talking about software that is still in development, so a degree of lattitude is required. The featureset of PHPUnit 3 is great. Here are a few notable features (in my mind):

  • Mock objects
  • Code Coverage Analysis
  • Multitude of test logging options
  • Built well for testing >php5 applications

Using the framework is an absolute breeze and there is excellent documentation in the form of a free book (draft version) written by Sebastian Bergmann and published by O’Reilly called "PHPUnit Pocket Guide." The API is also documented quite nicely and serves as a good second-source for learning how to do specific things.

The most impressive part of this experience in my mind was how runnable the software is straight out of CVS. Most of the time when I am crazy enough to use CVS version I always seem to get my copy of the source at a point where it is very unstable and requires tweaking just to get the software to fulfill its basic requirements. PHPUnit 3 on the other hand was able to run in it’s standard mode without a flaw. The only thing that was missing that I felt I needed was html reports for the pass/fail status of the unit tests. The report templates and code was already to a point however that it was actually fairly trivial for me to make the changes to it that I thought would be needed to make it work. I have since passed those changes along to Sebastian and they have been added to CVS, so html reports are now in the cvs version as well. It felt good to be able to contribute a little bit to a very worthwhile project.

Sebastian has posted about the new reporting features on his blog that include some screenshots so I won’t bother to rehash over all of that. You can just go check them out on his site.

Share
This entry was posted in PHP Testing. Bookmark the permalink.

3 Responses to Finally used PHPUnit and I like it

  1. Hello !

    I just wanted to let you know that, if interested, i’ll be very pleased to hear if you like the testing class I developed following the [b]TAP[/b] format but adding [b]HTML reporting[/b] and [b]code coverage[/b] using the wonderful XDebug.

    A first alpha is available at [url]http://logicoder.bountysource.com[/url]

  2. Stijn says:

    Can you elaborate on the reasons for ditching simpletest? I’m in the process of evaluating PHP unit test frameworks myself, and it seems simpletest has the advantage of a web test framework (albeit a simple one). It also has mock objects, so no win for PHPUnit there.

  3. mike.lively says:

    Well, just to clear up one thing really quick, PHPUnit 3 does have mock objects and most releases to date have been very stable. I have now used PHPUnit for the better part of 2 months with no problems. Zend framework has also just announced that they will be using phpunit3 for their unit tests. So even though it is in an alpha stage it can be considered excellent software.

    So, mock objects aren’t a problem. As far as web testing, there are other options, the one I currently use is Selenium. However, you can also use the SimpleBrowser object directly with PHPUnit if you so desire. Lastly, (and this can’t be depended on) I have began work on a web testing framework that is fully integrated with PHPUnit.

    Now, as for the reasons I chose to use PHPUnit. There are two really big reasons. The first (and most important) reason is that the style that PHPUnit 3 is written and the API that it reveals perfectly fits my style. This is just a matter of preference but it is important to use tools you can be comfortable with. The second reason is that I really wanted a testing framework that supports code coverage, which works like a charm in PHPUnit 3.

    Another thing to look at is how active phpunit development is compared to simpletest. Now this isn’t a hge deal because SimpleTest does what it does, does it well, and doesn’t absolutely NEED any other functionality. However it hasn’ seen a new release for quite some time. PHPUnit on the otherhand is on the verge of a 3.0 release and has alot of community users and a very responsive project lead when it comes to new features.

    (Please note this is nothing against Marcus B. It’s just a fact of life that some have more time to develop OSS than others. Marcus is a top-notch developer that created an excellent testing suite.)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>