95

Where can I find the specification of JUnit's XML output. My goal is to write a UnitTest++ XML reporter which produced JUnit like output.

See: "Unable to get hudson to parse JUnit test output XML" and "Hudson, C++ and UnitTest++"

Community
  • 1
  • 1
Gilad Naor
  • 20,752
  • 14
  • 46
  • 53
  • Could you provide some more information, which output do you mean? Probably an example or instruction how to get such an ouput? Thanks! – guerda Jan 16 '09 at 06:59
  • Is it for JUnit 4.x? Which TestRunner do you use? – guerda May 06 '09 at 07:55
  • if you had the time to write an XML reporter for UnitTest++, I would be interested if you can share it. – Vincent Nov 08 '10 at 16:57
  • 31
    I'm surprised to hear that seeking a specification or standard "tend[s] to attract opinionated answers ...". I can understand why discussion of a spec or standard would create such problems, but a spec itself is simply a concrete fact. Either it exists or it doesn't, and an answerer either knows where it exists or not. Given the importance of specs and standards in helping modern software -- the most complex artifacts people have ever built -- interoperate, I think that the SO guidelines should be altered to allow these types of questions. – Arthur Oct 19 '16 at 17:40
  • Whoever closed that ticket didn't understand the question, yet decided to take inappropriate actions which lowered again the quality of this website content, even though that probably wasn't his goal. – Johan Boulé Aug 31 '23 at 17:23

5 Answers5

57

You can find an XSD based on the code in Apache Ant 1.8.2 at https://github.com/windyroad/JUnit-Schema

Tom Howard
  • 6,516
  • 35
  • 58
  • 7
    See my commentary at https://windyroad.zendesk.com/entries/56354186-Your-open-source-JUnit-XSD for pieces missing from this XSD. – Reinderien Apr 23 '14 at 20:14
  • 1
    bringing the comment on-site, `Reinderien` found out that these are seems to be missing: `/testsuites/testsuite/@skipped`, `/testsuites/testsuite/testcase/skipped`, `/testsuites/testsuite/error`, `/testsuites/testsuite/failure`, `/testsuites/testsuite/system-err`, after readthrough of `XMLJUnitResultFormatter.java`, `XMLResultAggregator.java`, `XMLConstants.java` at http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/ – n611x007 Apr 22 '15 at 13:24
  • 2
    @naxa, I believe those nodes were added after Apache Ant 1.8.2. I recall being very thorough at the time (back at the begging of 2011). I've just moved the XSD to github and switched the license to the Apache License version 2.0. Feel free to fork and update. – Tom Howard Apr 27 '15 at 09:52
  • 1
    This was a huge help getting my custom C# testing application to output results in a way that Azure Devops pipelines could understand. – Lavamantis Jun 08 '23 at 22:05
13

The xml output is not generated by JUnit (at least, not the junit.jar), but by the junit ant task.
The relevant class is org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.

Laurent Doré
  • 390
  • 1
  • 5
  • 9
  • 2
    This is great. I'd love to see real documentation or a real spec, but otherwise there's nothing more authoritative than the source. – Greg Price Jul 19 '12 at 22:54
  • Interpretation of that source also requires reading http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.java . – Reinderien Apr 23 '14 at 18:12
  • Also read http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java since it's the source of the package and ID attributes. – Reinderien Apr 23 '14 at 19:23
9

I found some informal spec at http://ant.1045680.n5.nabble.com/schema-for-junit-xml-output-td1375274.html

HD.
  • 2,127
  • 1
  • 18
  • 15
  • 2
    yes, I've landed on that page too, but it's not complete. in extending RUnit (unit testing for R) so that it produces output compatible with Hudson, I ended up producing one "testsuites", there a list of "testsuite" and in these all "testcase". I still don't know how to mark deactivated tests. – mariotomo Sep 24 '10 at 13:54
7

As others have mentioned the xml is handled by ANT not jUnit

Here's the best spec I've seen. From this post

case nelson
  • 3,537
  • 3
  • 30
  • 37
-6

I can only give you an general information.

In the sourcecode of JUnit, you will find your information. If you provide some more information, I can help you further. My personal hint for finding your specification would be junit.framework.TestResult.

Good luck!

guerda
  • 23,388
  • 27
  • 97
  • 146