RESTful CI Integration with FitNesse

FitNesse offers RESTful command line services. In the past week I have worked on a solution to integrate these command line option in a Jenkins environment with the FitNesse plug-in. It turns out that this didn’t work as smooth as expected for me. I needed some special shell-fu to get the plugin and the most recent version of FitNesse working together. Here is how I did this, hoping that someone else will find my solution to help them in their aid.

The plug-in expects a test result from FitNesse in xml-format. It shall also contain the html-portions of the tests. The reporting plug-in will use the html-information to inform about the failed tests, what went wrong, and what went right.

RESTful calls

The RESTful services in FitNesse provide some functionality to put out all the necessary information for the Jenkins plug-in. For the RESTful service, we will need to append the option format=xml to print out the test results as xml-Format.

There is an undocumented switch to include the html-information from the actual tests, The option for including the actual html-information is called includehtml. By then we instruct FitNesse to append the html-output from each test to the resulting xml-file.

To execute the test suite in ExampleTestSuite we can run java -jar fitnesse.jar -p 12345 -c "ExmapleTestSuite?suite&format=xml&includehtml". Unfortunately this will produce an output on standard out, which also contains the information from FitNesse starting, and so on. So, just putting this command into a shell-execute step in Jenkins will not suffice.

AWK to the rescue

Also, if we simple write the contents of this command to a file, and try to read it in with the plugin, we will fail, since it will not produce a valid xml-file for the FitNesse Jenkins plug-in.

On a Linux box, you can use awk to strip out the necessary information from the FitNesse output. We instruct awk to print out everything between the opening <?xml>-tag and the closing </testResults>-tag with the following snipplet:

awk '/<\?xml/,<\/testResults>/ {print}'

Putting it all together

Using some pipes and output forwarding will create us a file which is processable by the Jenkins plug-in. Using the example from above, and forwarding the results to fitnesse_results.xml, we get the following code:

java -jar fitnesse.jar -p 12345 -c "ExmapleTestSuite?suite&format=xml&includehtml" | awk '/<\?xml/,<\/testResults>/ {print}' > fitnesse_results.xml

This solution also provides the advantage, that you can add excludeFilters to the call of the FitNesse suite. By then you can organize your tests in a test set for your regression tests with one particular tag, and the tests for the current sprint with another tag. You can then switch easily by varying the excluded tag from each suite. You can also use inclusive filters, and take advantage of the remaining filters available for the suite service. Please consult the FitNesse documentation on that.

Outlook

I hope I am able to provide a more convenient function for the next version of FitNesse. This approach does not work on all Windows boxes. I hope I can find some time to work on a feature in FitNesse that will provide this sort of behavior by default. Another way around this problem could be an adaptation of the Jenkins plug-in, but I don’t know, who wrote this, or how to contact them. For the time being, this description should help some folks, I hope.

  • Print
  • Twitter
  • LinkedIn
  • Google Bookmarks

5 thoughts on “RESTful CI Integration with FitNesse”

  1. Thanks Markus.

    Just a tiny amendment…

    When I run the command line as specified in the blog post, I get:

    awk: /<\?xml/,/ {print}
    awk: ^ syntax error
    awk: /<\?xml/,/ {print}
    awk: ^ backslash not last character on line

    I fixed it by adding a / after the coma. So:

    java -jar fitnesse.jar -p 12345 -c “ExmapleTestSuite?suite&format=xml&includehtml” | awk ‘/<\?xml/,// {print}’ > fitnesse_results.xml

  2. To run on Windows, I had to modify the awk command . I found the info I needed here: http://stackoverflow.com/a/17988834/18651

    So I used this command line:
    java -jar fitnesse.jar -p 12345 -c “ExmapleTestSuite?suite&format=xml&includehtml” | awk “/<?xml/{a=1}//{print;a=0}a” > fitnesse_results.xml

Leave a Reply to Rogier Goede Cancel reply

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