如何在testng的@Aftertest中获取testcase状态
如何在TestNg的@AfterTest注释中获取测试用例状态。如果测试用例在@postest中通过或失败,我需要采取一些措施如何在testng的@Aftertest中获取testcase状态,testng,Testng,如何在TestNg的@AfterTest注释中获取测试用例状态。如果测试用例在@postest中通过或失败,我需要采取一些措施 @AfterTest(alwaysRun=true) public void teardown(ITestContext test) throws Exception { String testcase = test.getCurrentXmlTest().getParameter("id"); } 问题在于ITestContext是全局的,而不是特定于测试的
@AfterTest(alwaysRun=true)
public void teardown(ITestContext test) throws Exception {
String testcase = test.getCurrentXmlTest().getParameter("id");
}
问题在于
ITestContext
是全局的,而不是特定于测试的。您需要的是有一个侦听器,并让它执行OnTestFailure
监听器提供了很多可能性,因此您可能希望对此进行研究 如果想要“更快”的解决方案,可以使用
ITestResult.getStatus()
以下是after方法的一个示例:
@AfterMethod
protected void afterMethod(ITestResult result, ITestContext testContext) {
if (result.getStatus() == ITestResult.FAILURE) {
//do something in case of fail
} else {
//do something else for success
}
}
不要忘记在参数中传递ITestResults!