我的Junit Test函数有try-catch块 . 在catch块中,我捕获异常以在ExtentReport中记录错误 . 另外,我正在从Apache ant'junitreport'生成Junit报告 . 我的问题是,因为我在catch块中捕获异常,所以生成的Junit结果不显示错误 . 如何抛出异常(或其他方式)来注册Junit结果的异常 .
这是代码:
try {
//Test code
} catch (Exception e) {
extentTest.log(LogStatus.ERROR, "Exception in clicking "); //For ExtentREport Logging
e.printStackTrace();
throw(new Exception(e.getMessage(), e)); //Expected Junit to capture error, but it is not happening
}
1 回答
而不是包装异常,你可以重新抛出它 .