Class XMLResultAggregator

  • All Implemented Interfaces:
    java.lang.Cloneable, XMLConstants

    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 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 Detail

      • filesets

        protected java.util.Vector<FileSet> filesets
        the list of all filesets, that should contains the xml to aggregate
      • toFile

        protected java.lang.String toFile
        the name of the result file
      • toDir

        protected toDir
        the directory to write the file to

        public static final java.lang.String DEFAULT_DIR
        The default directory: .. It is resolved from the project directory
        See Also:
        Constant Field Values

        public static final java.lang.String DEFAULT_FILENAME
        the default file name: TESTS-TestSuites.xml
        See Also:
        Constant Field Values
      • generatedId

        protected int generatedId
        the current generated id
    • Constructor Detail

      • XMLResultAggregator

        public XMLResultAggregator()
    • Method Detail

      • createReport

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

        public void setTofile​(java.lang.String value)
        Set the name of the aggregated results file. It must be relative from the todir attribute. If not set it will use DEFAULT_FILENAME
        value - the name of the file.
        See Also:
      • setTodir

        public void setTodir​( 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.
        value - the directory where to write the results, absolute or relative.
      • addFileSet

        public void addFileSet​(FileSet fs)
        Add a new fileset containing the XML results to aggregate
        fs - the new fileset of xml results.
      • execute

        public void execute()
                     throws BuildException
        Aggregate all testsuites into a single document and write it to the specified directory and file.
        execute in class Task
        BuildException - thrown if there is a serious error while writing the document.
      • getDestinationFile

        public getDestinationFile()
        Get the full destination file where to write the result. It is made of the todir and tofile attributes.
        the destination file where should be written the result file.
      • getFiles

        protected[] getFiles()
        Get all .xml files in the fileset.
        all files in the fileset that end with a '.xml'.
      • writeDOMTree

        protected void writeDOMTree​(org.w3c.dom.Document doc,
        Write the DOM tree to a file.
        doc - the XML document to dump to disk.
        file - the filename to write the document to. Should obviously be a .xml file.
        Throws: - thrown if there is an error while writing the content.
      • createDocument

        protected org.w3c.dom.Element createDocument()
        Create a DOM tree. Has 'testsuites' as firstchild and aggregates all testsuite results that exists in the base directory.
        the root element of DOM tree that aggregates all testsuites.
      • addTestSuite

        protected void addTestSuite​(org.w3c.dom.Element root,
                                    org.w3c.dom.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.

        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.