Package testUtils

Class TestResultsReporter

java.lang.Object
testUtils.TestResultsReporter
All Implemented Interfaces:
org.testng.IReporter, org.testng.ITestNGListener

public class TestResultsReporter extends Object implements org.testng.IReporter
Custom TestNG reporter that generates structured JSON reports for test execution results.

This reporter implements the IReporter interface to capture comprehensive test execution data and export it as JSON for integration with external test management systems and CI/CD pipelines.

Key Features:

  • Maps test methods to test case IDs using a configuration file
  • Handles both single execution and parameterized tests with multiple iterations
  • Captures test outcomes, execution durations, and detailed parameters
  • Exports results in structured JSON format
  • Provides null safety and error handling
Configuration:

The reporter expects a test-plan-suite.json file in the test resources directory with the following structure:


 {
   "testPlanName": "Automation Test Plan",
   "testSuiteName": "API Test Suite",
   "testCases": {
     "testMethodName": {
       "testCaseId": "TC-001"
     }
   }
 }
 
Output:

Generates a JSON report at test-results/test-results-report.json containing test execution summary and detailed results for each test case.

Since:
1.0
Author:
Nayeem John Y
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    collectTestResults(org.testng.IResultMap resultMap)
    Processes and collects test results from a TestNG result map.
    void
    generateReport(List<org.testng.xml.XmlSuite> xmlSuites, List<org.testng.ISuite> suites, String outputDirectory)
    Generates the test results report by processing all test suites and their results.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.testng.IReporter

    getConfig

    Methods inherited from interface org.testng.ITestNGListener

    isEnabled
  • Constructor Details

    • TestResultsReporter

      public TestResultsReporter()
  • Method Details

    • generateReport

      public void generateReport(List<org.testng.xml.XmlSuite> xmlSuites, List<org.testng.ISuite> suites, String outputDirectory)
      Generates the test results report by processing all test suites and their results.

      This method is automatically called by TestNG after all tests have completed. It performs the following operations:

      1. Loads test case mappings from the configuration file
      2. Processes all test results (passed, failed, skipped)
      3. Aggregates results for parameterized tests
      4. Generates and writes the final JSON report
      Specified by:
      generateReport in interface org.testng.IReporter
      Parameters:
      xmlSuites - list of XML suite configurations (not used in current implementation)
      suites - list of test suites containing execution results
      outputDirectory - directory where reports should be generated (not used, using fixed path)
    • collectTestResults

      public void collectTestResults(org.testng.IResultMap resultMap)
      Processes and collects test results from a TestNG result map.

      This method treats all test executions as iterations, whether they are parameterized or simple tests. Each test execution creates an iteration record.

      Parameters:
      resultMap - TestNG result map containing test execution results