请找到代码
Test(dataProvider = "User_login")
public void StatusForm_Verification(String uname, String pwd)
throws InterruptedException {
try {
NavigateToLogin();
Dashboard RD = LoginAs_user(uname, pwd);
Thread.sleep(2000);
if (Integer.parseInt(ReviewedStatuscount) >= 1) {
Assert.assertEquals("true",
revui.Btn_SaveReview.getAttribute("disabled"));
Assert.assertEquals("true",
revui.Btn_submitReview.getAttribute("disabled"));
Assert.assertEquals("true",
revui.Btn_Needmoreinfo.getAttribute("disabled"));
status = TestLinkAPIResults.PASSED;
} else {
throw new SkipException(
"Test Skipping - Reviewed count is Zero");
}
}catch((AssertionError ex) {
testlink_result = TestLinkAPIResults.TEST_FAILED;
msg = ex.getMessage();
}
}
执行上述方法时,如果在TestNG报告中抛出任何断言错误,则应该是FAIL状态 - 这是正确的
但如果我在上面的方法中使用Try catch块(捕获AssertionError),TestNG报告总是PASS状态,为什么?怎么样?
答案 0 :(得分:5)
我不熟悉TestLink,但在正常情况下,TestNG可以知道您的测试是否失败的唯一方法是捕获抛出的异常。当你在这里捕获异常时,你会“吞下”它,阻止它到达TestNG框架。
要解决此问题,请在执行TestLink处理后重新抛出异常,如下所示:
} catch (AssertionError ex) {
testlink_result = TestLinkAPIResults.TEST_FAILED;
msg = ex.getMessage();
// Rethrow the AssertionError to signal to TestNG that the test failed.
throw ex;
}