Dashboard > Pulse v2.1 > ... > Cookbook > CB - Integrating JUnit Results
  Pulse v2.1 Log In | Sign Up   View a printable version of the current page.  
  CB - Integrating JUnit Results
Added by Jason Sankey, last edited by Jason Sankey on Sep 16, 2009  (view change)
Labels: 
(None)

Pulse Manual Index

Overview

This article illustrates how to generate JUnit test reports with Ant, capture those reports as a build artifact and post-process the test results. This will integrate your JUnit test results into the pulse™ build result. The process differs for built-in projects as opposed to pulse file, both are described below.

Generating Reports With Ant

The easiest way to integrate your JUnit test results is to generate a single XML report for all of your test cases. This is achieved in two steps. First, specify XML formatting to the Ant Junit task, capturing XML reports for each test case to a reports directory. Then, use the Ant JUnit report task to combine these files into a single report. You may also want to use the JUnit report task to generate an HTML report at the same time. For example:

build.xml
<target name="test">
    <junit printsummary="yes">
        <classpath>
            <pathelement location="${classes.dir}"/>
            <pathelement location="${test.classes.dir}"/>
            <path refid="lib.path"/>
        </classpath>
        <formatter type="xml"/>
        <batchtest todir="reports/xml">
            <fileset dir="${test.dir}">
                <include name="**/*Test.java"/>
            </fileset>
        </batchtest>
    </junit>
    <junitreport todir="reports">
        <fileset dir="reports/xml">
            <include name="*.xml"/>
        </fileset>
        <report format="frames" todir="reports/html"/>
    </junitreport>
</target>

This target (adapted to your specific build file) will leave a report called TESTS-TestSuites.xml in the reports directory, and an HTML report for all tests in the reports/html directory.

Capturing the Report

Now you need to tell pulse™ to capture the XML report as an artifact, and to post-process it with a JUnit XML report post-processor. This is achieved differently for built-in versus pulse file projects.

Built-in Projects

Add a new directory artifact to your project to capture the XML report generated. From the project's configuration view, expand the "recipes, commands and artifacts" tree item and navigate down to the "artifacts" child item of the command that runs ant. Click the "add" link at the bottom of the "artifacts" table. Then:

  1. Select "file artifact" as the type.
  2. Name your artifact "junit xml report", set the file to "reports/xml/TESTS-TestSuites.xml" and add the "junit xml report processor".

Pulse File Projects

Capture the XML report in your pulse™ file where you execute the ant command:

pulse.xml
<?xml version="1.0"?>
<project default-recipe="default">
    <junit.pp name="junit"/>

    <recipe name="default">
        <ant name="test" targets="test">
            <artifact name="JUnit report" file="$(base.dir)/reports/xml/TESTS-TestSuites.xml">
                <process processor="$(junit)"/>
            </artifact>
        </ant>
    </recipe>
</project>

First, we define a JUnit post-processor using the junit.pp element. The artifact element is used to capture the report file, and the post-processor is applied to it. Now the test results will show up in the build result.

Extra Credit

You can also capture the HTML report, so that you can browse to it from the pulse™ UI.

Built-in Projects

Add another artifact, this time:

  1. Select "directory artifact" as the type.
  2. Name your artifact "junit html report", set the base directory to "reports/html", do not select any processors.

Pulse will automatically detect that the artifact is an HTML report and present it appropriately in the web interface.

Pulse File Projects

<ant name="test" targets="test">
    <artifact name="JUnit report" file="$(base.dir)/reports/xml/TEST-TestSuites.xml">
        <process processor="$(junit)"/>
    </artifact>
    <dir-artifact name="JUnit HTML report" base="$(base.dir)/reports/html"/>
</ant>

Zutubi wiki is Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators