本文介绍了在TestNG中执行后改变测试结果的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过@AfterClass 方法更改测试结果的状态.我的要求是使用 @test 标签运行一些 UI 测试,我需要在 @AfterClass 方法中验证所有这些测试的数据库,因为数据库需要一段时间才能更新.

Is it possible to change the status of a test result from @AfterClass method.My requirement is to run some UI tests using @test tag and I need to validate the DB for all those tests in the @AfterClass method, since the DB is taking a while to get updated.

推荐答案

你不能在 AfterClass 中做到这一点,但你可以利用一个监听器来做到这一点.试试 IInvokedMethodListener.实现以下方法:public void afterInvocation(IInvokedMethod method, ITestResult testResult)

You cannot do it in AfterClass, but you can utilize a listener to do this. Try out IInvokedMethodListener. Implement the following method : public void afterInvocation(IInvokedMethod method, ITestResult testResult)

结果对象可以在这里设置为任何值,基于一些检查(testResult.setStatus(status)).请注意,这将在每个方法之后执行.

The result object can be set here to whatever value, based on some checks (testResult.setStatus(status)). Note this would be executed after every method.

这篇关于在TestNG中执行后改变测试结果的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 04:10