Wednesday, October 20, 2010

Hudson-Ant+Groovy: Fitnesse integration

Earlier I wrote that I started to use Hudson instead of CruiseControl for building projects and running our acceptance tests. After having it around for a week, I’ve tentatively switch our builds to use it. Since my CruiseControl's builds are mainly ant scripts so it was pretty easy. I just moved them to Hudson.
You know that Ant is a platform-independent scripting tool that lets you construct your build scripts in much the same fashion as the "make" tool in C or C++. You can use a large number of built-in tasks in Ant without any customization: scp, sshexec, copy, waitfor, etc.
Such built-in tasks were the main reason why I made the decision at the time to use ant. And it was going well until the scripts become big and complex. Simple builds are easy to express as a series of tasks and dependencies. For such builds the facilities of ant work well. But more complex builds require conditional logic, and that requires more general programming language constructs. So I have been extremely annoyed by trying to use ant and it's XML config files.

The reason for that is XML's verbosity. It's not too bad for data files but the moment you try writing reasonably complex code the amount of typing you have to do quickly starts to becoming unusable for any real project. Once the scripts get complex enough having to do it in XML becomes really annoying.
So I started tinkering around and discovered Gant that is a tool for scripting Ant tasks using Groovy instead of XML to specify the logic. It was exactly that I had been looking for and it is supported by Hudson very well. So I completely replaced the build process removing all the Ant in favor of Groovy. It was not so hard as I can reuse my favorite Ant tasks for declarative operations but use a real scripting language for procedural logic. And it is very handy to do things like loops, subroutines and list collection in my build files. And In order not to sound proofless, I want to give you a real example.
One of my favorite features of Hudson is the ability to watch the console output of a build in progress, like this one:

I've already mentioned in my posts that we use FitNesse for Acceptance testing. And it was a task to integrate FitNesse within Hudson. Actually there is a plugin that facilitate execution and reporting on Fitnesse. But I don't like it as there is no any progress reporting for running test suites and results is not integrated in Hudson. So I decided to use groovy for the integration. And here is a result:

Now I am having the verbose progress reporting for running tests. As soon as there are red tests I see them in the console and optionally can get messaging by e-mail. The results are published in Hudson's page so there is a really cool build history graph that shows both the time it took to run tests and whether they passed or failed — makes it easy to see our build trends on the team.

Here is a groovy script that I use for it:

No comments:

Post a Comment