I need to retrieve test method status, actual result, expected result & other attributes in IReporter implementation. Is it possible to use ITestResult to pass required data to generateReport() method in IReporter implementation? Any other suggestion would be appreciated.

Sample test class as follows,

 public void methodOne() {

        //Values I want to pass to generateReport
        String testString01;
        String testString02;
        String testString03;

        //Status of the method one - pass/fail

testNG xml as follows,

<?xml version="1.0" encoding="UTF-8"?>
<suite name="TestRunner" verbose="1" configfailurepolicy="continue">

        <listener class-name="com.wsdscd.util.TestNGEmailableReport2"/>
    <test name="TestRunner">
            <class name="com.dsfscce.tests.poc.POC"></class>

IReporter implementation as follows,

public class TestNGEmailableReport2 implements IReporter {

    public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) {

//required to retrieve data method data here
//required to retrive suite information here 

1 Answer 1


For example using this way:

class MyReporter implements IReporter {
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
        List<ITestContext> testContexts = suites
                .flatMap(iSuite -> iSuite.getResults().values().stream())
                .map(iSuiteResult -> iSuiteResult.getTestContext())
        for(ITestContext testContext: testContexts){
            System.out.printf("Suite: " + testContext.getSuite().getName());
            Set<ITestResult> failedTests = testContext.getFailedTests().getAllResults();
            for(ITestResult iTestResult: failedTests){
                System.out.println("This test failed:" + iTestResult.getName();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.