gpt4 book ai didi

java - 获取 "java: incompatible types: java.lang.Object cannot be converted to org.testng.ISuiteResult"

转载 作者:行者123 更新时间:2023-12-02 04:25:16 25 4
gpt4 key购买 nike

我已经使用reportNg为我的自动化框架生成了结果报告,但这似乎并不方便,因为它没有在结果中显示测试用例描述。因此,我尝试使用 IReporter 接口(interface)生成自定义的 html 结果报告,但出现以下错误:

java:不兼容的类型:java.lang.Object 无法转换为 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());
}
}
}
}

最佳答案

您在此处使用原始 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)

org.testng.IReporter documentation 匹配...

关于java - 获取 "java: incompatible types: java.lang.Object cannot be converted to org.testng.ISuiteResult",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32269108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com