【发布时间】:2017-01-13 03:38:42
【问题描述】:
我希望我的测试重试 5 次,并且不超过 x 分钟。最后一次调用后,会调用@Aftermethod 中的mergeReport 方法。这是我的示例代码:
@Test(priority = 1, invocationCount = 5, invocationTimeOut = 6000, expectedExceptions = ThreadTimeoutException.class)
public void test() throws Exception {
while (true) {
Thread.sleep(1000);
}
}
@AfterMethod(lastTimeOnly = true, alwaysRun = true)
public void mergeReport(ITestResult result) throws Exception {
System.out.println("Report");
}
测试结果将为空。但是当我将invocationCount改为2时,测试结果会是:
Report
我在互联网上搜索,发现与 2014 年类似的问题,但仍然没有答案:https://github.com/cbeust/testng/issues/325
有人遇到过这个问题吗?
【问题讨论】:
-
我不确定 325 是不是类似的问题。你能打开一个新的并在那里提供一个完整的可运行项目吗?
-
我通过使用 TestListenerAdapter 和 IInvokedMethodListener 解决了这个问题。如果在达到 invocationCount = 5 之前测试超时,我的自定义侦听器会将其设置为 5,并且将触发 after 方法。
while (iTestResult.getMethod().getCurrentInvocationCount() < iTestResult.getMethod().getTotalInvocationCount()) { iInvokedMethod.getTestMethod().incrementCurrentInvocationCount(); }