2

请找到代码

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 状态,为什么?如何?

4

1 回答 1

6

我不熟悉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;
}
于 2013-07-26T17:46:59.380 回答