org.apache.tools.ant.taskdefs.optional.junit

Class XMLResultAggregator

public class XMLResultAggregator extends Task implements XMLConstants

Aggregates all <junit> XML formatter testsuite data under a specific directory and transforms the results via XSLT. It is not particulary clean but should be helpful while I am thinking about another technique.

The main problem is due to the fact that a JVM can be forked for a testcase thus making it impossible to aggregate all testcases since the listener is (obviously) in the forked JVM. A solution could be to write a TestListener that will receive events from the TestRunner via sockets. This is IMHO the simplest way to do it to avoid this file hacking thing.

UNKNOWN: name="junitreport" category="testing"

Field Summary
static StringDEFAULT_DIR
The default directory: ..
static StringDEFAULT_FILENAME
the default file name: TESTS-TestSuites.xml
protected Vectorfilesets
the list of all filesets, that should contains the xml to aggregate
protected intgeneratedId
the current generated id
protected FiletoDir
the directory to write the file to
protected StringtoFile
the name of the result file
protected Vectortransformers
Method Summary
voidaddFileSet(FileSet fs)
Add a new fileset containing the XML results to aggregate
protected voidaddTestSuite(Element root, Element testsuite)

Add a new testsuite node to the document.

protected ElementcreateDocument()

Create a DOM tree.

AggregateTransformercreateReport()
Generate a report based on the document created by the merge.
voidexecute()
Aggregate all testsuites into a single document and write it to the specified directory and file.
FilegetDestinationFile()
Get the full destination file where to write the result.
protected File[]getFiles()
Get all .xml files in the fileset.
voidsetTodir(File value)
Set the destination directory where the results should be written.
voidsetTofile(String value)
Set the name of the aggregegated results file.
protected voidwriteDOMTree(Document doc, File file)
Write the DOM tree to a file.

Field Detail

DEFAULT_DIR

public static final String DEFAULT_DIR
The default directory: .. It is resolved from the project directory

DEFAULT_FILENAME

public static final String DEFAULT_FILENAME
the default file name: TESTS-TestSuites.xml

filesets

protected Vector filesets
the list of all filesets, that should contains the xml to aggregate

generatedId

protected int generatedId
the current generated id

toDir

protected File toDir
the directory to write the file to

toFile

protected String toFile
the name of the result file

transformers

protected Vector transformers

Method Detail

addFileSet

public void addFileSet(FileSet fs)
Add a new fileset containing the XML results to aggregate

Parameters: fs the new fileset of xml results.

addTestSuite

protected void addTestSuite(Element root, Element testsuite)

Add a new testsuite node to the document. The main difference is that it split the previous fully qualified name into a package and a name.

For example: org.apache.Whatever will be split into org.apache and Whatever.

Parameters: root the root element to which the testsuite node should be appended. testsuite the element to append to the given root. It will slightly modify the original node to change the name attribute and add a package one.

createDocument

protected Element createDocument()

Create a DOM tree. Has 'testsuites' as firstchild and aggregates all testsuite results that exists in the base directory.

Returns: the root element of DOM tree that aggregates all testsuites.

createReport

public AggregateTransformer createReport()
Generate a report based on the document created by the merge.

Returns: the report

execute

public void execute()
Aggregate all testsuites into a single document and write it to the specified directory and file.

Throws: BuildException thrown if there is a serious error while writing the document.

getDestinationFile

public File getDestinationFile()
Get the full destination file where to write the result. It is made of the todir and tofile attributes.

Returns: the destination file where should be written the result file.

getFiles

protected File[] getFiles()
Get all .xml files in the fileset.

Returns: all files in the fileset that end with a '.xml'.

setTodir

public void setTodir(File value)
Set the destination directory where the results should be written. If not set if will use DEFAULT_DIR. When given a relative directory it will resolve it from the project directory.

Parameters: value the directory where to write the results, absolute or relative.

setTofile

public void setTofile(String value)
Set the name of the aggregegated results file. It must be relative from the todir attribute. If not set it will use DEFAULT_FILENAME

Parameters: value the name of the file.

See Also: setTodir

writeDOMTree

protected void writeDOMTree(Document doc, File file)
Write the DOM tree to a file.

Parameters: doc the XML document to dump to disk. file the filename to write the document to. Should obviouslly be a .xml file.

Throws: IOException thrown if there is an error while writing the content.