JUnit Adaptor - Improvement
The out of the box JUnit adaptor was not working with the output from my ant script. Perhaps this is because it was written for JUnit 3 and not JUnit 4?
In any case, here is the adaptor I wrote. This is sample code and comes with no IBM support, however, it might help you. Please test it thoroughly!
Here is what the end result will look like in the Bill of Materials:
(Note the picture is cropped in the forum, click here to see a full size http://i.imgur.com/3PNbe.png)
http://i.imgur.com/3PNbe.png
Here is a sample JUnit ant file plus some JUnit 4 test suite and test cases:
http://dl.dropbox.com/u/3905048/junit-sample.zip
Here is the JUnit adaptor which parses the XML output file created from running the ant script.
In any case, here is the adaptor I wrote. This is sample code and comes with no IBM support, however, it might help you. Please test it thoroughly!
Here is what the end result will look like in the Bill of Materials:
(Note the picture is cropped in the forum, click here to see a full size http://i.imgur.com/3PNbe.png)
Here is a sample JUnit ant file plus some JUnit 4 test suite and test cases:
http://dl.dropbox.com/u/3905048/junit-sample.zip
Here is the JUnit adaptor which parses the XML output file created from running the ant script.
<?xml version="1.0"?>
<!--
Created by Benjamin Chodroff, 2011
benjamin.chodroff@us.ibm.com
Sample Code - Not supported by IBM. Do not use in production without thorough testing!
-->
<!DOCTYPE PROJECT_INTERFACE SYSTEM "interface.dtd">
<PROJECT_INTERFACE IFTYPE="Test" INSTANCE="7.02">
<template>
<!-- Template section, these are parsed out of the final xml and used to populate an
existing environment group if an instance of this interface is linked with a project.
However, use the list below to help identify the variables needed to run this interface
if you are integrating it during a regular BuildForge step.
-->
<env name="ANT_HOME" value="/opt/apache-ant-1.8.2/" />
<env name="JAVA_HOME" value="/usr/java/jdk1.7.0" />
<env name="ANT_TEST_TARGET" value="all"/>
<env name="DIR" value="$BF_STEP_ROOT"/>
<env name="OUTPUT" value="build/test.results/test.result.xml"/>
</template>
<interface>
<run command="test" params="${DIR} ${ANT_HOME} ${ANT_TEST_TARGET} ${OUTPUT}" server="$BF_SERVER" dir="." timeout="360" />
<ontempenv name="ErrorsOccurred" state="hastext">
<step result="FAIL"/>
</ontempenv>
<ontempenv name="FailuresOccurred" state="hastext">
<step result="FAIL"/>
</ontempenv>
</interface>
<command name="test">
<execute>
cd $1
pwd
$2/bin/ant $3
cat $4
</execute>
<resultsblock beginpattern="&lt;testsuite" endpattern="&lt;/testsuite&gt;">
<match pattern="&lt;testsuite\s+errors=&quot;(\d+)&quot;\s+failures=&quot;(\d+)&quot;\s+hostname=&quot;(.+)&quot;\s+name=&quot;(.+)&quot;\s+tests=&quot;(\d+)&quot;\s+time=&quot;(.+)&quot;\s+timestamp=&quot;(.+)&quot;">
<bom category="unit_test" section="overview">
<field name="errors" text="$1"/>
<field name="failures" text="$2"/>
<field name="hostname" text="$3"/>
<field name="name" text="$4"/>
<field name="tests" text="$5"/>
<field name="time" text="$6"/>
<field name="timestamp" text="$7"/>
</bom>
<setenv name="FailuresOccurred" value="true" type="temp" condition="true($2>0)"/>
<setenv name="ErrorsOccurred" value="true" type="temp" condition="true($1>0)"/>
</match>
<!-- if a testcase ends in /> we know it was a success and is summarized in one line-->
<resultsblock beginpattern="&lt;testcase.+/&gt;" endpattern="/&gt;">
<match pattern="&lt;testcase\s+classname=&quot;(.+)&quot;\s+name=&quot;(.+)&quot;\s+time=&quot;(.+)&quot;\s+/&gt;">
<bom category="unit_test" section="details">
<field name="classname" text="$1"/>
<field name="name" text="$2"/>
<field name="time" text="$3"/>
<field name="success" text="true"/>
<field name="message" text=" "/>
<field name="type" text=" "/>
</bom>
</match>
</resultsblock>
<!-- if a testcase ends in </testcase> we know it was a failure and should have a <failure> block -->
<resultsblock beginpattern="&lt;testcase.+&quot;&gt;" endpattern="&lt;/testcase&gt;">
<match pattern="&lt;testcase\s+classname=&quot;(.+)&quot;\s+name=&quot;(.+)&quot;\s+time=&quot;(.+)&quot;">
<bom category="unit_test" section="details">
<field name="classname" text="$1"/>
<field name="name" text="$2"/>
<field name="time" text="$3"/>
<field name="success" text="false"/>
</bom>
</match>
<match pattern="&lt;failure\s+message=&quot;(.+)&quot;\s+type=&quot;(.+)&quot;">
<bom category="unit_test" section="details">
<field name="message" text="$1"/>
<field name="type" text="$2"/>
</bom>
</match>
</resultsblock>
</resultsblock>
</command>
<bomformat category="unit_test" title="JUnit Tests">
<section name="overview" expandable="true">
<field order="1" name="errors" title="Errors"/>
<field order="2" name="failures" title="Failures"/>
<field order="3" name="hostname" title="Hostname"/>
<field order="4" name="name" title="Test Suite Name"/>
<field order="5" name="tests" title="Number of Tests"/>
<field order="6" name="time" title="Elapsed Time"/>
<field order="7" name="timestamp" title="Timestamp"/>
</section>
<section name="details" parent="overview">
<field order="1" name="classname" title="Classname"/>
<field order="2" name="name" title="Name"/>
<field order="3" name="time" title="Elapsed Time"/>
<field order="4" name="success" title="Success"/>
<field order="5" name="message" title="Error message"/>
<field order="6" name="type" title="Error type"/>
</section>
</bomformat>
</PROJECT_INTERFACE>