【发布时间】:2016-08-03 12:06:39
【问题描述】:
我有一个针对特定功能的测试类,并有多层测试类,它们被视为 BaseClass,其中发生驱动程序初始化和测试启动(我在这里避免使用 Listener)。在 BaseClass 中定义了一个 AfterMethod,它注销并使用异常和堆栈跟踪捕获结果并记录到数据库,如果测试失败我能够捕获异常,如果 BeforeMethod 或 BeforeClass 失败,则不会捕获异常,所有我请参阅显示为已跳过的测试状态。这是我在 AfterMethod 中使用的一段代码:
public void afterMethodBase(ITestResult result) {
logger.debug("TestName : " + result.getTestName());
logger.info("Method Name : " + result.getMethod().getMethodName());
ResultLogger.processResult(result);
Throwable exception = itr.getThrowable(); // this is null when status is skipped
}
如何捕获BeforeMethod 或BeforeClass 中引发的异常
【问题讨论】: