Skip to content

Fun with FitNesse

June 21, 2011

I’ve dabbled a bit with FitNesse over the years, but have recently concentrated more on unit testing (with GoogleTest and GoogleMock). I’m now working on a Java web app and FitNesse seems like just the thing for putting some acceptance tests in place. So, I downloaded FitNesse and started looking around for a fixture that would talk http (and maybe https). I quickly came across a fixture called HtmlFixture, which is built on top of HtmlUnit. Download and installation was trivial and I was soon up and running with my straw-man acceptance test.

Of course, this is just the point at which problems start. I wanted to build the URL to retrieve within the body of the test, based on the test setup – not an unreasonable requirement. HtmlFixture requires the URL to be specified in the first cell of the first row after the table heading, and I couldn’t find a way of generating the URL in a preceding table and then using it HtmlFixture. FitNesse has enhanced the ColumnFixture to allow storing and retrieving values as named ‘Symbols’, but HtmlFixture is derived from Fixture itself, so no joy there (although more on this later).

And, while there is lots of ‘documentation’ about FitNesse it does suffer from that peculiar affliction of all Wikis I’ve dealt with – rot. The information is hard to find, non-authoritative and sometimes down-right confusing (for instance FitNesse now runs against EITHER a Slim server or a Fit server). There’s also a book “Fit for developing software”, by two of the original writers of the software, but this was published in 2005 and is a bit long in the tooth – though still indispensable. The index also leaves a lot to be desired.

Meanwhile, the HtmlFixture site is billed as being “Improved”, but the Command Reference starts with the not-entirely-confidence-inspiring sentence: “The following documentation is accurate, but incomplete.” And indeed, it lived up to this promise, so, it was off to Sourceforge to have a look at the one true documentation – the source code.

Next day: time to write some code:

  • Derive a fixture from HtmlFixture.
  • Override doTable
    • Do preprocessing to build the required URL
    • Manipulate the Parse tree to put the URL where HtmFixture’s doTable method expects it
    • Pass the Parse tree to super.doTable

 The Parse class is part of Fit and, though the source code is open for inspection, it was a diagram in the ‘Architecture’ section at the back of the “Fit for developing software” book that actually helped me traverse the tree successfully. Without that I know I would have struggled for quite a bit longer.

The test now works as expected, and all is good. Closer inspection of the source and documentation of HtmlFixture show that there is functionality to support the use of Symbols as variables. This should allow me to refactor the code, so that the URL building gets done in, say, a SetUpFixture, leaving a vanilla HtmlFixture to execute the http GET and check the response.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: