Different types of listeners

There are many different types of interfaces that allow us to modify TestNG behavior. Listed next are these interfaces:

  • ITestListener: A listener used for listening on running tests.
  • ISuiteListener: A listener used specifically for test suites.
  • IReporter: This is an interface to be implemented if a report has to be generated.
  • IMethodInterceptor: This is used to change the collection of methods that TestNG is going to execute.
  • IInvokedMethodListener: This gets into action before and after a test method is invoked by TestNG.
  • IHookableIf this interface is implemented by a class, then the run() method will be invoked instead of the @test method. The test method will be performed when the callBack() method of the IHookCallBack parameter is invoked.
  • IAnnotationTransformerThe transform method will be invoked by TestNG to give you a chance to modify a TestNG annotation read from your test classes. You can change the values by calling any of the setter methods on the ITest interface.
  • IAnnotationTransformer2: If any other test annotation needs to be modified apart from the @Test annotation, one can use this interface.

We will mainly be looking at the iTestListener and iSuiteListener interface implementations.

There are two ways in which TestNG listeners can be used:

  • By extending the TestListenerAdapter class
  • By implementing the corresponding interface, iTestListener

Let's understand both methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset