Take the 2-minute tour ×

Im trying to access the org.testng.reporters.XMLReporter from my Java code. I am writing code with eclipse plugin and I am new to testNG.

I have a simple class with a @BeforeSuite, @AfterSuite and 1 @Test (Just as a demo) I thought I could simply add Reporter.getOutput(); to my @AfterSuite method which looks like it returns a list but it is always null. I assume I need a listener but im not sure where or how to add it.

My end goal is to access the XML results that get generated in a file by default to write to my own test DB I have created I can parse the XML since its generated by default I would rather do it all in code.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

I'm not sure what you're trying to do. If you want to access the generated XML, why not do this in a SuiteListener? Or even in a process that gets run after TestNG has finished?

share|improve this answer
I guess thats my question I am not sure how to do this is a suite listener. –  ducati1212 Aug 30 '11 at 20:43
The results in the generated XML file contain the exact info I want to store. I was starting to write a XML parser that got the results file from disk after a test ran and parsed it into my DB format. I would much rather be able to do that in my test code rather than reading the file. –  ducati1212 Aug 30 '11 at 20:53
Either you parse the XML or you create your own SuiteListener (or better, IReporter) which will receive the result of the entire suite in Java. From there, you can do whatever you want. –  Cedric Beust Sep 1 '11 at 16:17
add comment

To add a suite listner you have to follow these step. 1. Create a class implementing ISuiteListner.

public class PlatformSuiteManager implements ISuiteListener {
  1. Add the listener to the testng.xml or if you are running a through maven surefire add listner to the xml.

For TestNg.xml suite add following tag to indicate a listner

    <listener class-name="com.example.PlatformSuiteManager" />
    <listener class-name="com.example.MyMethodInterceptor" />

For sure fire add following under configuration tab


If you need to do a report listner you have to implement IReporter

public class PlatfornReportManager implements IReporter {

public void generateReport(List xmlSuites, List iSuites, String s) { //Implementaion }


I think this answers how to add suite listner and how to add report listner.

Note that report listner is called at the end of the suite.

Please make a sound if this is not clear to you

Please answer me to generate report using default listener. tell me default listeners of TestNG

share|improve this answer
add comment

Your Answer


