TestNG的IInvokedMethodListener监听器详解

来源:互联网 发布:csol由于网络设定问题 编辑:程序博客网 时间:2024/05/17 02:26

在TestNG的执行过程中,通过IInvokedMethodListener监听器,能够在调用某个测试方法之前或者之后发出通知。

目前,该监听器只支持调用如下测试方法时发出通知:

  • @Test方法
  • Configuration方法,即@Before*方法和@After*方法

IInvokedMethodListener监听器中定义了如下两个方法,分别表示在被调用的测试方法之前或之后发出通知:

void beforeInvocation(IInvokedMethod method, ITestResult testResult);void afterInvocation(IInvokedMethod method, ITestResult testResult);

此外,TestNG还提供了IInvokedMethodListener2监听器,其中定义的两个方法还提供了加入用户信息的参数,如下所示:

void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context);void afterInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context);

IInvokedMethodListener监听器的实现,以及在TestNG中的使用,与其他监听器类似。



1 0