[geeklog-devel] Introducing Geeklog Unit Tests and Continuous Integration

Dirk Haun dirk at haun-online.de
Sat Aug 14 09:12:55 EDT 2010


We have quite the backlog of GSoC projects that we still have to integrate into Geeklog or otherwise adopt. So it's my pleasure to announce that a project from GSoC 2009 has quietly been put into use:

Sean Clark developed a unit test framework for Geeklog, based on PHPUnit and with its own GUI.

The plan was to set it up to run automatically on one of our servers so that the tests would be run for every new commit to the Geeklog repository (aka Continuous Integration). Well, we (i.e. mostly: I) never got it to work in the somewhat restricted environment on our servers and so it was put aside. A few weeks ago, I decided to give it another go, this time using a tool that I'm more familiar with: Hudson.

Hudson is now running on <http://project.geeklog.net:8080/>, monitoring the Geeklog repository and running the unit test framework for every commit.

Right now, it's only running some 200 unit tests, mostly for the files in system/classes and lib-mbyte.php. Sean also wrote some tests for lib-common.php, including the infrastructure to use an XML database instead of the real one. I haven't set that part up yet but will do so at a later point (after FrOSCon).

What does this all mean? As a Geeklog developer, your commit will now be run against a set of unit tests. If you make a change to one of the files under test, you may very well break a test - in which case you should look into the problem and fix it. I haven't set up Hudson to send out emails yet, but there are a couple of RSS feeds that you can subscribe to to stay informed.

200 tests doesn't sound like much. But hey, that's 200 more than we had until now. That's also 200 fewer cases where we could accidentally break something without noticing it. Once we get into the habit of adding tests for changes or new functionality that we introduce, that number will steadily go up, covering more and more of Geeklog's code.

So, I'd like to encourage people to write new unit tests. Personally, I find writing unit test quite enjoyable. They're usually just a couple of lines, so you can easily crank out a few at a time. Even if you don't find any bugs[1] in the code you're testing, it's very satisfying to see the total number of tests go up and to know that you did something to improve the overall quality of Geeklog.

To get started, you need the unit test framework project:

http://project.geeklog.net/cgi-bin/hgwebdir.cgi/test-framework/

Installation instructions are included. Note that you don't need Hudson! You can run the tests from the command line or use the included GUI. Next, read Sean's introduction:

http://wiki.geeklog.net/index.php/Test_Suite

Run a few tests. Review some of the existing ones. Try to think of tests to add (for an existing test class or start a new one). Happy testing!

bye, Dirk

[1] <http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/6e081d4eb47d>




More information about the geeklog-devel mailing list