What are Default Listeners in TestNG?


TestNG Listeners have the capacity to listen to a specific incident. It is basically an interface that changes the nature of the system. TestNG Listeners are used for logging purposes and creating reports.

TestNG can be configured with the Listeners which can change the default behavior of the TestNG. There are several interfaces that allows to modify TestNG's behavior. These interfaces are broadly called "TestNG Listeners".

Here are a few listeners:

  • IAnnotationTransformer

  • IAnnotationTransformer2

  • IHookable

  • IInvokedMethodListener

  • IMethodInterceptor

  • IReporter

    • generateReport(java.util.List<XmlSuite> xmlSuites, java.util.List<ISuite> suites, java.lang.String outputDirectory) - Generate a report for the given suites into the specified output directory.

  • ISuiteListener

    • onFinish(ISuite suite) − This method is invoked after the SuiteRunner has run all the test suites.

    • onStart(ISuite suite) − This method is invoked before the SuiteRunner starts.

  • ITestListener

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

    • onStart(ITestContext context) − Invoked after the test class is instantiated and before any configuration method is 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.

These are commonly used default listeners in TestNG. This list keeps updating and evolving time to time.

To find the latest listeners supported by TestNG please visit the official page:

https://testng.org/#_testng_documentation

User can find the list of listeners here. However to get into more details of each listeners, click on javadoc/doc, it will bring the detailed documentation of each listeners.

Updated on: 04-Mar-2024

135 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements