1 回答

TA貢獻1963條經驗 獲得超6個贊
為了獲取實例,我創建了 TestNg CustomListener 類,在其中我手動將輸入參數 (TestCase) 設置為每個已執行測試 ITestResult 的屬性:
public class CustomListener extends TestListenerAdapter {
@Override
public void onTestFailure(ITestResult iTestResult) {
super.onTestFailure(iTestResult);
TestCase tCase = (TestCase) iTestResult.getParameters()[0];
iTestResult.setAttribute("failed_case", tCase);
}
@Override
public void onTestSuccess(ITestResult iTestResult) {
super.onTestSuccess(iTestResult);
TestCase tCase = (TestCase) iTestResult.getParameters()[0];
iTestResult.setAttribute("passed_case", tCase);
}
@Override
public void onTestSkipped(ITestResult iTestResult) {
super.onTestSkipped(iTestResult);
TestCase tCase = (TestCase) iTestResult.getParameters()[0];
iTestResult.setAttribute("skipped_case", tCase);
}
}
在我的自定義報告類中,我獲取每個測試用例的對象,如下所示:
TestCase failedCase = (TestCase) testResult.getAttribute("failed_case");
TestCase passedCase = (TestCase) testResult.getAttribute("passed_case");
TestCase skippedCase = (TestCase) testResult.getAttribute("skipped_case");
添加回答
舉報