本文介紹了如何在測試失敗后停止運行TestNG的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試用TestNG編寫一個測試方法,失敗后,整個測試套件將停止運行。
@Test
public void stopTestingIfThisFailed() throws Exception
{
someTestStesp();
if (softAsserter.isOneFailed()) {
asserter.fail("stopTestingIfThisFailed test Failed");
throw new Exception("Test can't continue, fail here!");
}
}
正在引發異常,但其他測試方法正在運行。
如何解決此問題?
推薦答案
我是這樣解決問題的:在一定不能失敗的測試之后-我正在將數據寫入臨時文本文件。
稍后,在下一個測試中,我在@BeforeClass中添加了代碼,用于檢查前面提到的文本文件中的數據。如果找到顯示停止程序,我將終止當前進程。
如果”不能”測試實際失?。?/p>
public static void saveShowStopper() {
try {
General.createFile("ShowStopper","tempShowStopper.txt");
} catch (ParseException e) {
e.printStackTrace();
}
}
@BeforeClass驗證代碼:
@BeforeClass(alwaysRun = true)
public void beforeClass(ITestContext testContext, @Optional String step, @Optional String suiteLoopData,
@Optional String group) throws Exception
{
boolean wasShowStopperFound = APIUtils.loadShowStopper();
if (wasShowStopperFound){
Thread.currentThread().interrupt();
return;
}
}
這篇關于如何在測試失敗后停止運行TestNG的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,