我希望我的測試重試5次,但不超過x分鐘。在最後一次調用之後,它將在@After方法中調用mergeReport方法。這裏我的示例代碼:@AfterMethod方法使用invocationTimeOut和invocationCount> 2(TestNG 6.9 - > 6.10)時未執行
@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是一個類似的問題。你能否開一個新的項目並在那裏提供一個完整的可運行項目? – juherr
我使用TestListenerAdapter和IInvokedMethodListener修復了此問題。如果在測試超時達到invocationCount = 5之前,我的自定義偵聽器將其設置爲5,並且將觸發after方法。 '(iTestResult.getMethod()。getCurrentInvocationCount()