繁体   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