TestNG - Test Results


Advertisements

Reporting is the most important part of any test execution, as it helps the user understand the result of the test execution, point of failure, and the reasons for 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 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.

In this chapter, we will have four different examples to demonstrate four different cases of reporting and logging −

Sr.No. Case & Example
1 Custom Logging

This example illustrates how to write your own logger.

2 Custom Reporter

This example illustrates how to write your own reporter.

3 HTML and XML report

This example illustrates the default HTML and XML report generated by TestNG.

4 JUnit Reports

This example illustrates how to generate JUnit reports from TestNG reports.

Advertisements