Class XMLResultAggregator
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator
- All Implemented Interfaces:
Cloneable, XMLConstants
Aggregates all <junit> XML formatter testsuite data under
a specific directory and transforms the results via XSLT.
It is not particularly 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default directory:..static final Stringthe default file name:TESTS-TestSuites.xmlthe list of all filesets, that should contains the xml to aggregateprotected intthe current generated idprotected Filethe directory to write the file toprotected Stringthe name of the result fileprotected Vector<AggregateTransformer> Fields inherited from class ProjectComponent
description, location, projectFields inherited from interface XMLConstants
ATTR_CLASSNAME, ATTR_ERRORS, ATTR_FAILURES, ATTR_ID, ATTR_MESSAGE, ATTR_NAME, ATTR_PACKAGE, ATTR_SKIPPED, ATTR_TESTS, ATTR_TIME, ATTR_TYPE, ATTR_VALUE, ERROR, FAILURE, HOSTNAME, PROPERTIES, PROPERTY, SYSTEM_ERR, SYSTEM_OUT, TESTCASE, TESTSUITE, TESTSUITES, TIMESTAMPModifier and TypeFieldDescriptionstatic final Stringclassname attribute for testcase elementsstatic final Stringerrors attribute for testsuite elementsstatic final Stringfailures attribute for testsuite elementsstatic final Stringid attributestatic final Stringmessage attribute for failure elementsstatic final Stringname attribute for property, testcase and testsuite elementsstatic final Stringpackage attribute for the aggregate documentstatic final Stringstatic final Stringtests attribute for testsuite elementsstatic final Stringtime attribute for testcase and testsuite elementsstatic final Stringtype attribute for failure and error elementsstatic final Stringvalue attribute for property elementsstatic final Stringthe error elementstatic final Stringthe failure elementstatic final Stringname of host running the testsstatic final Stringthe properties elementstatic final Stringthe property elementstatic final Stringthe system-err elementstatic final Stringthe system-out elementstatic final Stringthe testcase elementstatic final Stringthe testsuite elementstatic final Stringthe testsuites element for the aggregate documentstatic final Stringtimestamp of test cases -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileSet(FileSet fs) Add a new fileset containing the XML results to aggregateprotected voidaddTestSuite(Element root, Element testsuite) Add a new testsuite node to the document.protected ElementCreate a DOM tree.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.Get the full destination file where to write the result.protected File[]getFiles()Get all.xmlfiles in the fileset.voidSet the destination directory where the results should be written.voidSet the name of the aggregated results file.protected voidwriteDOMTree(Document doc, File file) Write the DOM tree to a file.Methods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProjectModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.voidsetProject(Project project) Sets the project object of this component.
-
Field Details
-
filesets
-
toFile
the name of the result file -
toDir
the directory to write the file to -
transformers
-
DEFAULT_DIR
The default directory:.. It is resolved from the project directory- See Also:
-
DEFAULT_FILENAME
-
generatedId
protected int generatedIdthe current generated id
-
-
Constructor Details
-
XMLResultAggregator
public XMLResultAggregator()
-
-
Method Details
-
createReport
Generate a report based on the document created by the merge.- Returns:
- the report
-
setTofile
Set the name of the aggregated results file. It must be relative from thetodirattribute. If not set it will useDEFAULT_FILENAME- Parameters:
value- the name of the file.- See Also:
-
setTodir
Set the destination directory where the results should be written. If not set if will useDEFAULT_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.
-
addFileSet
Add a new fileset containing the XML results to aggregate- Parameters:
fs- the new fileset of xml results.
-
execute
Aggregate all testsuites into a single document and write it to the specified directory and file.- Overrides:
executein classTask- Throws:
BuildException- thrown if there is a serious error while writing the document.
-
getDestinationFile
Get the full destination file where to write the result. It is made of thetodirandtofileattributes.- Returns:
- the destination file where should be written the result file.
-
getFiles
Get all.xmlfiles in the fileset.- Returns:
- all files in the fileset that end with a '.xml'.
-
writeDOMTree
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 obviously be a .xml file.- Throws:
IOException- thrown if there is an error while writing the content.
-
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.
-
addTestSuite
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.Whateverwill be split intoorg.apacheandWhatever.- Parameters:
root- the root element to which thetestsuitenode 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.
-