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:
<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 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" tab, click the "add new artifact link" at the bottom of the "artifacts" table. This will take you to the Artifact Wizard. In step 1, name your artifact "junit xml report" and choose "file artifact" as the type. In step 2 set the file to reports/xml/TESTS-TestSuites.xml. Finally, in step 3, check the box for the JUnit XML report post-processor.
Pulse File Projects
Capture the XML report in your pulse™ file where you execute the ant command:
<?xml version="1.0"?>
<project default-recipe="default">
<junit.pp name="junit"/>
<recipe name="default">
<command name="test">
<ant targets="test"/>
<artifact name="JUnit report" file="${base.dir}/reports/xml/TESTS-TestSuites.xml">
<process processor="${junit}"/>
</artifact>
</command>
</recipe>
</project>
First, we define a JUnit post-processor using the junit.pp element. Then, we wrap the ant element in a command element, so that we can specify artifacts to capture. 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, using the Artifact Wizard. In step 1, set the name to "junit html report" and select "directory artifact" as the type. In step 2, set the base directory to "reports/html". Do not select on post-processors in step 3. Pulse will automatically detect that the artifact is an HTML report and present it appropriately in the web interface.
Pulse File Projects
<command name="test">
<ant 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"/>
</command>