簡體   English   中英

僅在我的@Test通過時運行@AfterMethod,而不是在@Test失敗時運行

[英]Run @AfterMethod only when my @Test is passed, not if @Test fails

我的afterMethod由以下afterMethod組成:

@AfterMethod(groups = { "Regression" })
public void afterMethod() {
    // Setting driver used to false as this test case is pass
    driverUsed.put("supportDriver", false);
    System.out.println("Test case is pass");
}

我把驅動程序false

但是我希望只在我的@Test通過時才運行afterMethod ,而不是@test失敗時。

引用TestNG的文檔

任何@AfterMethod方法都可以聲明一個ITestResult類型的參數,它將反映剛剛運行的測試方法的結果。

您可以使用此參數來檢查測試是否成功:

@AfterMethod(groups = { "Regression" })
public void afterMethod(ITestResult result) {
   if (result.getStatus() == ITestResult.SUCCESS) {
        // Setting driver used to false as this test case is pass
        driverUsed.put("supportDriver", false);
        System.out.println("Test case is pass");
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM