• Home
  • Testing
  • SAP
  • Web
  • Must Learn!
  • Big Data
  • Live Projects
  • AI
  • Blog

Report generation is very important when you are doing the Automation Testing as well as for Manual Testing.

  • By looking at the result, you can easily identify how many test cases are passed, failed and skipped.
  • By looking at the report, you will come to know what the status of the project is.

Selenium web driver is used for automating the web-application, but it won't generate any reports.

  • The TestNG will generate the default report.
  • When you execute testng.xml file, and refresh the project. You will get test-output folder in that folder.
  • Right click on the emailable-report.html and select the option. Open with the web browser.

In this tutorial, you will learn-

Method-1: emailable-report.html

  1. Click on option "emailable-report.html"
  2. Click on option web browser

The output report of testng will look like below if both the classes are passed:

Consider the scenario in where you are intentionally failing the test case i.e. DemoB class. Then convert both the classes into testng.xml suite file and run it. Then the result will look like this. It will show the failed test cases.

This is result for DemoB class:

Similarly, result for the Class DemoA will look like this:

Method-2 index.html

  1. Right click on the index.html from the project directory.
  2. Select option open with web browser option. It will display the result in the following order.

The result will look like this:

Method-3 Reporter Class

Along with these report generated methods, you can use object.properties file to store the system generated logs as well as user generated logs. But one of the simplest ways to store log information in testing is using Reporter Class.

Reporter is a class present in TestNG. It provides 4 different methods to store log information they are:

  1. Reporter.log(String s);
  2. Reporter.log(String s, Boolean logToStandardOut);
  3. Reporter.log(String s, int level);
  4. Reporter.log(String s, int level, Boolean logToStandardOut);

Example:

Create Two classes such as DemoA and DemoB and write the following code inside the classes.

For Class DemoA;

  • The Code for DemoA is already explained above. Here you are using log method of Reporter class. (For implementing a reporting class, the class has to implement an org.testng.IReporter interface).
  • The log method is a static method of Reporter class. So you are accessing that method through the Reporter class.
  • The log method is used to store log information that is written inside the program. By looking at the log information, you will easily come to know where exactly the execution of the program is stopped.

For Class DemoB:

  • Now, Create testng.xml file by selecting these two classes and
  • Select run as and
  • Click on the convert to testng.
  • Then run this testng.xml file by selecting run as and select testng suite.
  • Then refresh the project open the test-output folder.
  1. In the test-output folder, open the emailable-report.html. It will look like:

Similarly, you will have an Output for Demo B project as well.

2. In test-output folder open the index.html. It will look like:

Click on reporter output. It will open logging info whatever written in the test methods.

Click on the Times. It will going to show how much time it took to run the test method present in class.

 

YOU MIGHT LIKE: