Publish JUnit Report

Version 4 by Steve Luo
on Feb 16, 2012 06:59.


compared with
Current by Steve Luo
on Feb 16, 2012 07:05.


 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 3 changes. View first change.

 To publish [JUnit|http://www.junit.org] report, you only need two steps:
 # Generate JUnit *XML* report from [Ant|http://ant.apache.org] or [Maven|http://maven.apache.org] or any other build tool.
 # Add a JUnit report publish step by choosing _Publish -> Junit Report_ in step menu.
  
 h2. Generate JUnit Report
  
 QuickBuild will NOT generate [JUnit|http://www.junit.org] report automatically, so first make sure the [JUnit|http://www.junit.org] report is produced by [ANT|http://ant.apache.org] or by any other build tool. The following example shows how to generate JUnit test results with [Ant JUnit task|http://ant.apache.org/manual/OptionalTasks/junit.html] and aggregate all the test reports into one by using [Ant JUnitReport task|http://ant.apache.org/manual/OptionalTasks/junitreport.html] (this is not required):
 {code:xml|title=JUnit target in build.xml}
 <target name="junit" depends="compile.test">
  <mkdir dir="${junit.report.dir}" />
  <mkdir dir="${junit.report.dir}/test-out" />
  <record name="${junit.report.dir}/test-output.txt" append="no" action="start"/>
  <junit printsummary="yes" haltonfailure="false" fork="yes">
  <classpath refid="test.classpath"/>
  <formatter type="xml"/>
  <batchtest fork="yes" todir="${junit.report.dir}/test-out">
  <fileset dir="${test.home}">
  <include name="**/*Test.java"/>
  <exclude name="**/*AbstractTest.java"/>
  </fileset>
  </batchtest>
  </junit>
  <junitreport todir="${junit.report.dir}">
  <fileset dir="${junit.report.dir}/test-out">
  <include name="TEST-*.xml"/>
  </fileset>
  </junitreport>
  <record name="${junit.report.dir}/test-output.txt" action="stop"/>
 </target>
 {code}
 The code snippet will generate the XML reports for each test case, and the reports will be captured to '$\{junit.report.dir\}' directory.
  
 {note:title=About haltonfailure}
 If 'haltonfailure' in junit task is defined to true, the junit reports are not complete. If you want to generate the full reports, set 'haltonfailure' to false.
 {note}
  
 h2. Publish JUnit Report
 Add _*Publish JUnit Report*_ step to your build workflow. If you have several report sets, you can add several publish JUnit steps with different report set names. Reference [this page|Publish Build Reports] for more details.
  
 h2. Supported JUnit-style Report
 For those who are willing to output JUnit-style XML report by yourself, below illustrates the format supported in QuickBuild:
  
 h3. Testcase element
  
 {code:xml}
 <testcase classname="xxx" name="xxx" time="xxx">
  <system-out>some sys out message if any</system-out>
  <system-err>some sys err message if any</sys-err>
   
  <error type="xxx">
  some error message if any
  </error>
  <failure type="xxx">
  some failure message if any
  </failure>
  <skipped /> <!-- if this test case is skipped -->
 </testcase>
 {code}
  
The system-out and system-err are not generated by JUnit, so you can use them to output the message only for this testcase and QuickBuild can display them. classname should also include package name, QuickBuild only parse the classname attribute to generate the package name.
  The system-out and system-err are not generated by JUnit, so you can use them to output the message only for this testcase and QuickBuild can display them. classname should also include package name, QuickBuild only parse the classname attribute to generate the package name. The attribute time is the duration of a test case which should be in milliseconds.
  
 All child elements: system-out, system-err, error, failure, skipped are optional. The status of test case depends on one of error, failure or skipped element, if none of them, then the test is passed.
  
 h3. Testsuite element
 {code:xml}
 <testsuite classname="xxx" package="xxx" tests="xxx" time="xxx">
  <testcase ...>
  </testcase>
  ...
  <ignored-testcase ...> <!-- test case is ignored -->
  </ignored-testcase>
  <system-out />
  <system-err />
 </testsuite>
 {code}
  
 Here, you may use classname only without package attribute, that is, package name will be parsed from attribute _classname="com.pmease.quickbuild.DummyTest_ if there is no package attribute presented. tests attribute and time attribute are optional, QuickBuild will accumulate all test cases and their duration automatically.
  
 The attribute system-out and system-err are for all test cases in this test suite and will be displayed for all test cases in it.
  
 If you have multiple test suites in one report, then a root element <testsuites> should be used, like below:
 {code:xml}
 <testsuites>
  <testsuite ...>
  </testsuite>
  ... ...
  <testsuite ...>
  </testsuite>
 </testsuites>
 {code}