TestNG - Test Results


Reporting is the most important part of any test execution, reason being it helps the user to understand the result of the test execution, point of failure, and reasons for the failure. Logging, on the other hand, is important to keep an eye on the execution flow or for debugging in case of any failures.

TestNG by default generates a different type of report for its test execution. This includes an HTML and an XML report output. TestNG also allows its users to write their own reporter and use it with TestNG. There is also an option to write your own loggers, which are notified at runtime by TestNG.

There are two main ways to generate a report with TestNG:

  • Listeners : For implementing a listener class, the class has to implement the org.testng.ITestListener interface. These classes are notified at runtime by TestNG when the test starts, finishes, fails, skips, or passes.

  • Reporters : For implementing a reporting class, the class has to implement an org.testng.IReporter interface. These classes are called when the whole suite run ends. The object containing the information of the whole test run is passed to this class when called.

The table below lists examples for different cases of reporting and logging:

Custom LoggingThis example illustrates how to write your own logger.
Custom ReporterThis example illustrates how to write your own reporter.
HTML and XML reportThis example illustrates the default HTML and XML report generated by TestNG.
JUnit ReportsThis example illustrates the about generating Junit reports from TestNG reports.