Download to get rid of those pesky bugs.             MXUnit Unit Testing framework for ColdFusion developers                               Download       Details       Home       Support       Blog

MXUnit TestResult output formats

MXUnit provides a high level of flexibility by providing test results in various output formats. Some of these are preformatted, such as HTML, and others are raw to allow developers to generate customizable output formats.

The available TestResult output formats are:

  1. HTML Format
  2. ExtJs Format
  3. XML Format
  4. JUnit Report XML
  5. ColdFusion Query Format
  6. ColdFusion Array format

We will use the MXUnit example found in the installation package mxunit/samples/MyTestSuite.cfm as the base TestResults. You may want to refer to your local TestResult API for details; e.g., http://localhost:8500/mxunit/doc/api/

The syntax for generating the various types of output is:

<cfset output = results.getResultsOutput( ['html', 'extjs', 'xml', 'junitxml', 'query', 'array'] ) />
<cfoutput>#output#<cfoutput>
Note: Since the above query and array types are complex data structures, you will get an error by trying to print those directly, as illustrated above. You most likely be computing other outputs if you use those types.

Following are simple examples of how to handle the various output types.

Note that in order to toggle between HTML and ExtJs format, pass in a URL.output=['html'|'extjs'] to your TestSuite

1. HTML Format
The HTML output is basic preformatted HTML:

<cfoutput>#results.getResultsOutput( 'html' )#<cfoutput>

2. ExtJs Format

ExtJs is a rich user interface set of APIs written in JavaScript.

<cfoutput>#results.getResultsOutput( 'extjs' )#<cfoutput>

3. XML Format
This is basic raw XML format that can be transformed into custom HTML output.

<cfoutput>#results.getResultsOutput( 'xml' )#<cfoutput>

4. JUnit Report XML
This is an XML format that is used by Ant's JunitReport Task. Also see the MXUnit Ant Task for usage information.

<cfoutput>#results.getResultsOutput( 'junitxml' )#<cfoutput>

5. ColdFusion Query Format
Returns a CF Query object that you can loop over as if it were a database query.

 <cfset q = results.getResultsOutput( 'query' ) />
 <cfoutput query="q">
   #q.component#, #q.testStatus# ...
 </cfoutput>
The available columns names: COMPONENT, CONTENT, DATETIME, DEBUG, ERROR, NUMBER, TESTNAME, TESTSTATUS, TIME, TRACE.
Summary data members ( q = results.getResultsOutput('query') ) :
         q.testRuns = How many tests were run,
         q.failures = How many tests fail,
         q.errors = How many errors occurred,
         q.successes = How many successes occurred,
         q.totalExecutionTime = How long it took, in milliseconds, to run all the tests

<cfdump var="#results.getResultsOutput( 'query' )#" />

6. ColdFusion Array Format
This is how internal test results are stored within the TestResult component.
To access specific members, you can execute the following:

 <cfset a = results.getResultsOutput( 'array' ) />
 <cfoutput>
   #a[1]["component"]#, #a[1]["testStatus"]# ...
 </cfoutput>
 
<cfdump var="#results.getResultsOutput( 'array' )#" />

[Next - Running entire directories of Tests with one line of code!]

2008 MXUnit.org