TestNG | Listener types

Learn about the different Listener types available.

ISuiteListener

The Suite Listener method includes the methods onStart() and onFinish(). Whenever a class implements this listener, TestNG guarantees you that it will invoke the methods onStart() and onFinish() before and after running a TestNG Suite. Before TestNG picks up your suite for execution, it first makes a call to the onStart() method and runs whatever has been scripted in this method. In a similar way, it again makes a call to the onFinish() method after a suite has been run.

ITestListener

This Listener defers from ISuiteListerner, but the only difference is that it makes the call before and after the Test method, not the Suite. These are the methods:

  • onStart(): Invoked after the test class is instantiated and before any configuration method is called.

  • onFinish(): Invoked after all the tests have run and all their Configuration methods have been called.

  • onTestFailedButWithinSuccessPercentage(ITestResult result): Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.

  • onTestFailure(ITestResult result): Invoked each time a test fails.

  • onTestSkipped(ITestResult result): Invoked each time a test is skipped

  • onTestStart(ITestResult result): Invoked each time before a test will be invoked.

  • onTestSuccess(ITestResult result): Invoked each time a test succeeds.

IInvokedMethodListener

The working of this listener is also exactly the same as ISuiteListerner and ITestListerner. The only difference is that it makes the call before and after every Method. It only includes two methods:

  • afterInvocattion(): Invoke after each method

  • beforeInvocation(): Invoke before each method

In the following articles, you can find an index of how to implement each of the TestNG Listeners types, depending of your needs: