我已经使用reportNg为我的自动化框架生成了结果报告,但这似乎并不方便,因为它没有在结果中显示测试用例描述。因此,我尝试使用IReporter
界面生成自定义的html结果报告,但我收到以下错误:
java: incompatible types: java.lang.Object cannot be converted to org.testng.ISuiteResult
使用以下代码:
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());
}
}
}
}
答案 0 :(得分:2)
您在此处使用原始Map
类型:
Map suiteResults = suite.getResults();
您应该指定类型参数:
Map<String, ISuiteResult> suiteResults = suite.getResults();
或者假设您没有使用除下一行之外的变量,只需内联它:
for (ISuiteResult sr : suite.getResults().values())
您的方法签名也需要做同样的事情:
public void generateReport(
List<XmlSuite> xmlSuites,
List<ISuite> suites,
String outputDirectory)