我已經爲我的自動化框架生成了使用reportNg的結果報告,但這看起來並不方便,因爲它沒有顯示結果中的測試用例描述。因此,我試圖使用生成接口IReporter
定製HTML結果報告,但我發現了以下錯誤:在使用下面的代碼獲取「java:incompatible types:java.lang.Object無法轉換爲org.testng.ISuiteResult」
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());
}
}
}
}
*請*把一些時間到格式化你的代碼 - 這是非常,非常努力,沒有任何indentatio閱讀ñ。 –