XNSIO
  About   Slides   Home  

 
Managed Chaos
Naresh Jain's Random Thoughts on Software Development and Adventure Sports
     
`
 
RSS Feed
Recent Thoughts
Tags
Recent Comments

Integrating Fitnesse with CruiseControl

On the current project we use Fitnesse for Acceptance and Unit Integration testing. We rely quite heavily on the Fitnesse tests results to certify our builds. Hence it was important for us to automate running our fit tests and to properly publish our fit test result in the cruise page.

cruise page

Following are the simple steps you need to follow to do the same.

The general steps involved in the process:

  1. Start Fitnesse as a demon process in our build
  2. Invoke Fitnesse‘s TestRunner class with following
    2.a Specify XML as the output format and the path to the XML file [You can give both XML and HTML as the output format]
    2.b Host and Port on which Fitness is running
    2.c The path to the Fitnesse Test Suite URL [Ex: FrontPage.TestSuite]
  3. Configure CruiseControl to include this XML test results file
  4. Write XSLT [stylesheet] to display the results correctly

The logic behind starting Fitnesse as a demon process is, you do not want your build process to depend on external service. It is quite easy to start Fitnesse from your build process. Following is the Fitnesse target from the ANT build file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<br />
&lt;target name="smoke" description="Run fitnesse acceptance tests."&gt;<br />
&lt;property name="fitnesse.output.file" value="${fitnesse.output.dir}/fitnesse-test-results" /&gt;<br />
&lt;property name="fitnesse.port" value="8765" /&gt;<br />
&lt;path id="fitpath"&gt;<br />
&lt;fileset dir="${fitnesse_root_dir}"&gt;<br />
&lt;include name="fitnesse.jar" /&gt;<br />
&lt;include name="**/lib/*.jar" /&gt;<br />
&lt;/fileset&gt;<br />
&lt;!-- Add any other jars that your app might need --&gt;<br />
&lt;/path&gt;<br />
&lt;echo message="About to run fitnesse server" level="info" /&gt;<br />
&lt;parallel&gt;<br />
&lt;daemons&gt;<br />
&lt;java classname="fitnesse.FitNesse" classpath="${fitnesse_root_dir}/fitnesse.jar;${ant.home}/lib/xercesImpl.jar"&gt;<br />
&lt;arg value="-l" /&gt;<br />
&lt;arg value="${fitnesse_log_dir}" /&gt;<br />
&lt;arg value="-p" /&gt;<br />
&lt;arg value="${fitnesse.port}" /&gt;<br />
&lt;arg value="-e" /&gt;<br />
&lt;arg value="0" /&gt;<br />
&lt;arg value="-d" /&gt;<br />
&lt;arg value="${dir_containing_FitNesseRoot_dir}" /&gt;<br />
&lt;/java&gt;<br />
&lt;/daemons&gt;<br />
&lt;sequential&gt;<br />
&lt;echo message="sleeping for 10 seconds to let FitNesse server start" level="info" /&gt;<br />
&lt;sleep seconds="10" /&gt;<br />
&lt;java classpathref="fitpath" classname="fitnesse.TestRunner" fork="true" dir="${fitnesse_root_dir}" resultproperty="fit.test.failures"&gt;<br />
&lt;arg value="-debug" /&gt;<br />
&lt;arg value="-xml" /&gt;<br />
&lt;arg value="${fitnesse.output.file}.xml" /&gt;<br />
&lt;arg value="-html" /&gt;<br />
&lt;arg value="${fitnesse.output.file}.html" /&gt;<br />
&lt;arg value="-nopath" /&gt;<br />
&lt;arg value="localhost" /&gt;<br />
&lt;arg value="${fitnesse.port}" /&gt;<br />
&lt;arg value="${Fitnesse.Test.Page.Path}" /&gt;<br />
&lt;!-- Ex: FrontPage.TestSuite Please note that this page must exist else Fitnesse will execute System.exit(1) if it cannot find the page mentioned here --&gt;<br />
&lt;/java&gt;<br />
&lt;replace file="${fitnesse.output.file}.html" token="&lt;base href=&amp;quot;http://localhost:${fitnesse.port}/&amp;quot;/&gt;" /&gt;<br />
&lt;echo message="Finished FIT tests: ${fit.test.failures} failures/exceptions" level="info" /&gt;<br />
&lt;fail message="FIT test failures/exceptions: ${fit.test.failures}"&gt;<br />
&lt;condition&gt;<br />
&lt;not&gt;<br />
&lt;equals arg1="${fit.test.failures}" arg2="0" /&gt;<br />
&lt;/not&gt;<br />
&lt;/condition&gt;<br />
&lt;/fail&gt;<br />
&lt;!-- This will fail the build if the return code was not Zero, which means there were errors or exceptions --&gt;<br />
&lt;/sequential&gt;<br />
&lt;/parallel&gt;<br />
&lt;/target&gt;<br />

Adding this to your build file, will enable you to run Fitnesse tests from your ant build file.

The next step is to configure CruiseControl‘s config.xml file to specify the XML file, so that the test results are displayed on the front page

Changes to your project in the config.xml:

1
2
3
4
5
6
7
8
9
<br />
&lt;log dir="logs/${project.name}"&gt;<br />
&lt;merge file="path_to_fitnesse_output_file.xml"/&gt;<br />
...<br />
&lt;/log&gt;<br />
&lt;publishers&gt;<br />
&lt;artifactspublisher dir="fitnesse_report_output_dir" dest="artifacts/${project.name}"  subdirectory="fitnesse"/&gt;<br />
...<br />
&lt;/publishers&gt;<br />

  • The merge statement will enable Cruise to parse the .xml file and show the test result summary on the front page.
  • The artifactspublisher statement will copy the .xml and .html file to the artifacts folder. You should be able to click on the artifacts link on the Cruise Page and see the fitnesse_result_output_file.html under the fitnesse folder.
  • You will also have to copy the files folder from FitNesseRoot into /webapps/cruisecontrol folder. This will ensure that correct stylesheet [css] file is available to the resultant fitnesse_output html file. This file will be accessible from the Cruise Build Results page under the Build Artifacts/fitnesse link.

On the CruiseControl build page, the XML is formatted using a style sheet.


    Licensed under
Creative Commons License