TestNG Reports


TestNG generates a default HTML report once the test cases are executed. These reports helps to analyze and share the test results in a structured format. TestNG reports categorized the test results in to 3 status flags namely passTest, failTest and skipTest. 

Types of TestNG Reports Generated

When TestNG test scripts are executed through the command line using mvn test, the following reports are generated:

emailable-report.html – A summary dashboard that is suitable for sharing.
index.html – A detailed execution report including all test cases and their statuses.

If you're using Maven as the build tool, these reports will be found inside the target folder.
If you're using a Java project without Maven, the reports will be generated in the test-output folder.



Using Reporter Class in TestNG

You can log custom messages into the TestNG reports using the Reporter class.

Reporter Class Overview

The Reporter class in TestNG provides methods to log messages, which are then displayed in the generated HTML reports. This helps in enhancing the report's readability and debugging.

Methods in Reporter Class

Here are the commonly used methods:

Reporter.log(String s);
Reporter.log(String s, int level);
Reporter.log(String s, boolean logToStandardOut);
Reporter.log(String s, int level, boolean logToStandardOut);


     String s – The message to log.
     int level – Priority level of the log.
     boolean logToStandardOut – Whether to print it in the console as well.

Example: Logging Custom Message

Reporter.log("Login test started");

Embedding Screenshots in Reports

You can also embed screenshots for failed tests or important steps using Reporter.log():

Reporter.log("Reporter.log("<br><a href='path/to/screenshot.png'><img src='path/to/screenshot.png' height='100' width='100'/></a>");
")

 

Related Tutorials