JUnit does not generate XML reports. There is no standard XML output format for JUnit.
Other tools generate XML, such as Ant / Maven. So, the first thing you need to do is decide what form of the XML file you want, as in what you want to do with the files after they are created.
And, in fact, your restriction programmatically does not exclude ANT. You can program ant programmatically (see Call ant from java and then return to java after ant completes ). This would probably be the easiest way to generate ant -compatible files.
If you want to create your own XML files, you can create a class that extends RunListener and then runs your tests by calling JUnitCore # run () or similar.
public void main(String... args) { JUnitCore core= new JUnitCore(); core.addListener(new RingingListener()); core.run(MyTestClass.class); }
Your RunListener will just emit the appropriate XML. This is pretty easy to understand: override testRunStarted () methods, etc. And write out XML. For an example of how this works, see TextListener , which does the same for text.
Matthew farwell
source share