Friday, October 26, 2018

What is the use of TestNG Listeners?

As the name "Listeners" indicating they listen to some events and act accordingly. TestNG provides some interface that will help us to do certain tasks that before and after Suite or Test execution, these interfaces are nothing but TestNG Listeners.

TestNG Listeners are mainly used in generating customized reports and logs. Below are the list of listeners provided TestNG. Each interface is having different abstract methods which can be overridden as per our requirement.

  • IExecutionListener
    • This TestNG Listener monitors the begining and ending of the TestNG run. This has two methods onExecutionStarts() and onExecutionEnd(). onExecutionStarts() method will be invoked before TestNG starts executing the test suites and onExecutionEnd() method will be invoked after TestNG finishes executing all the test suites.
  • IAnnotationTransformer
    • This TestNG Listener allows us to modify TestNG annotations and configure further.
  • IInvokedMethodListener
    • This TestNG Listener is for all the methods. It will be invoked before and after of any method of TestNG.
  • IMethodInterceptor
    • This TestNG Listener is used to modify the list of test methods to be run in TestNG. We can select group of test methods from the given list using this and ignore other test methods.
  • IHookable
    • This TestNG Listener is used to implement your test methods with specific security manager. If a test class implements this interface, its run() method will be invoked instead of each @Test method found.
  • IReporter
    • This TestNG Listener is used for generating the report at the end of test suite execution.
  • ISuiteListener
    • This TestNG Listener is for test suite and this listener contains two methods onStart() and onFinish(). onStart() method will be invoked before executing the Suite and onFinish() will be invoked at the end of the Suite execution.
  • ITestListener
    • This TestNG Listener is for test method and this contains methods onStart(), onFinish(), onTestSuccess(), onTestFailure(), onTestSkipped() and onTestFailedButWithinSuccessPercentage().
In the next posts we will see the implementations of the some of the above listeners for better understanding.

Please comment your suggestions or queries on this post. Thanks for reading. #HappyTesting #HappyLearning #QABABU

No comments:

Post a Comment

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...