Getting "java: incompatible types: java.lang.Object cannot be converted to org.testng.ISuiteResult"

I have generated the result reports using reportNg for my automation framework but that does not seems to be handy as it does not shows the testcase description in the results. Therefore, I am trying to generate the customized html result report using IReporter interface, but I'm getting the below error:

java: incompatible types: java.lang.Object cannot be converted to org.testng.ISuiteResult

while using below code:

import java.util.List;
import java.util.Map;
import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
public class CustomReporter implements IReporter {
    @Override
    public void generateReport(List xmlSuites, List suites,
                               String outputDirectory) {
        //Iterating over each suite included in the test
        for (ISuite suite : suites) {
           //Following code gets the suite name
            String suiteName = suite.getName();
            //Getting the results for the said suite
            Map suiteResults = suite.getResults();
            for (ISuiteResult sr : suiteResults.values()) { //issue comes here
                ITestContext tc = sr.getTestContext();
                System.out.println("Passed tests for suite '" + suiteName +
                                   "' is:" + tc.getPassedTests().getAllResults().size());
                System.out.println("Failed tests for suite '" + suiteName +
                                   "' is:" +
                                   tc.getFailedTests().getAllResults().size());
                System.out.println("Skipped tests for suite '" + suiteName +
                                   "' is:" +
                                   tc.getSkippedTests().getAllResults().size());
            }
        }
    }
}
Jon Skeet
people
quotationmark

You're using the raw Map type here:

Map suiteResults = suite.getResults();

You should specify the type arguments:

Map<String, ISuiteResult> suiteResults = suite.getResults();

Or given that you're not using the variable other than for the next line, just inline it:

for (ISuiteResult sr : suite.getResults().values())

You need to do the same thing for your method signature, too:

public void generateReport(
    List<XmlSuite> xmlSuites,
    List<ISuite> suites,
    String outputDirectory)

That matches the org.testng.IReporter documentation...

people

See more on this question at Stackoverflow