EXTENTREPORTS HTML DASHBOARD: THREADLOCAL TELEMETRY & TESTNG HOOKS

Architect standalone, enterprise-grade HTML execution dashboards in REST Assured: ExtentReports 5.x SparkReporter integration, ThreadLocal<ExtentTest> state isolation across parallel TestNG threads, pretty-printed JSON/XML payload injection via MarkupHelper.createCodeBlock(), tabular header rendering, ITestListener event hooking, and zero-footprint report generation.

πŸ“ˆ Self-Contained Reporting, Wire Payloads & Parallel Test Telemetry

While Allure provides interactive dashboards with CLI servers, many enterprise testing environments require completely standalone, single-file HTML reports that can be emailed directly to stakeholders, hosted on static S3 buckets, or archived as CI artifacts without running specialized CLI server daemons. ExtentReports 5.x (SparkReporter) offers an industry-standard visual reporting solution for Java test frameworks. However, in concurrent REST Assured execution suites, sharing an ExtentTest instance causes log collisions and mangled test timelines across worker threads. By encapsulating active tests in a ThreadLocal<ExtentTest> container, wiring test events through a customized TestNG ITestListener, and utilizing MarkupHelper.createCodeBlock() to format outbound request payloads and inbound JSON responses with syntax highlighting, automation architects deliver high-fidelity API execution dashboards with complete thread safety.

1. ExtentReports 5.x Architecture & ThreadLocal Execution Topography
The architectural blueprint of ExtentReports SparkReporter in a parallel test environment, demonstrating how a global ExtentReports engine distributes isolated ExtentTest instances into ThreadLocal containers for concurrent TestNG workers.
ExtentReports ThreadLocal Lifecycle Architecture
EXTENTREPORTS 5.x THREADLOCAL CONCURRENCY & EVENT LIFECYCLE:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SINGLETON EXTENTREPORTS ENGINE (Global Suite Lifecycle Scope)                                 β”‚
β”‚ ExtentSparkReporter spark = new ExtentSparkReporter("target/ExtentReports/ExtentReport.html") β”‚
β”‚ ExtentReports extent = new ExtentReports(); extent.attachReporter(spark);                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                                                β–Ό (ITestListener onTestStart: Spawns ExtentTest)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ExtentTestManager: private static final ThreadLocal<ExtentTest> extentTestThreadLocal         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β–Ό                                                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ WORKER THREAD-1 (Student Registration Test)  β”‚      β”‚ WORKER THREAD-2 (Curriculum Catalog Test)    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. extentTestThreadLocal.set(t1)             β”‚      β”‚ 1. extentTestThreadLocal.set(t2)             β”‚
β”‚ 2. Dispatches POST /v1/students              β”‚      β”‚ 2. Dispatches GET /v1/curriculum             β”‚
β”‚ 3. Logs Wire Request via MarkupHelper:       β”‚      β”‚ 3. Logs Wire Request via MarkupHelper:       β”‚
β”‚    ExtentTestManager.logRequest(reqBody)     β”‚      β”‚    ExtentTestManager.logRequest(queryParams) β”‚
β”‚ 4. Logs Wire Response via MarkupHelper:      β”‚      β”‚ 4. Logs Wire Response via MarkupHelper:      β”‚
β”‚    ExtentTestManager.logResponse(respJson)   β”‚      β”‚    ExtentTestManager.logResponse(respJson)   β”‚
β”‚ 5. ITestListener onTestSuccess / onTestFail  β”‚      β”‚ 5. ITestListener onTestSuccess / onTestFail  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                                                β–Ό (Suite Complete: ISuiteListener / onFinish)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STANDALONE HTML REPORT COMPILATION: extent.flush() ──► target/ExtentReports/ExtentReport.html β”‚
β”‚  β”œβ”€β”€ Executive Summary Dashboard: Pie charts, Pass/Fail metrics, category distributions       β”‚
β”‚  β”œβ”€β”€ Chronological Timeline: Execution steps, millisecond durations per API call              β”‚
β”‚  └── Syntax-Highlighted Code Blocks: Outbound JSON request and inbound response payloads      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Architectural Standard: ExtentReports is thread-safe at the engine level (ExtentReports instance), but ExtentTest logging methods are stateful per test method. Wrapping ExtentTest in a ThreadLocal prevents thread cross-talk and ensures request/response payloads match their executing test.
Real-Time Example 1: Maven POM Setup for ExtentReports 5.x & SparkReporter
Configuring Maven dependencies for ExtentReports 5.x. Imports extentreports with modern Spark reporting capabilities, avoiding legacy version conflicts with third-party libraries.
XML (pom.xml ExtentReports 5.x Dependency Configuration)
<!-- ==============================================================================
     MAVEN POM.XML: EXTENTREPORTS 5.x DEPENDENCIES
============================================================================== -->
<properties>
    <extentreports.version>5.1.1</extentreports.version>
    <testng.version>7.9.0</testng.version>
    <restassured.version>5.4.0</restassured.version>
</properties>

<dependencies>
    <!-- ExtentReports 5.x Core & SparkReporter Engine -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>${extentreports.version}</version>
    </dependency>

    <!-- REST Assured Core Dependency -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>${restassured.version}</version>
        <scope>test</scope>
    </dependency>

    <!-- TestNG Testing Framework -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${testng.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>
Dependency Note: ExtentReports 5.x includes the SparkReporter module directly inside the core artifact, deprecating the older ExtentHtmlReporter from ExtentReports 3.x/4.x.
Real-Time Example 2: Thread-Safe ExtentManager & ExtentTestManager Singletons
Building thread-isolated management classes. Demonstrates configuring ExtentManager to initialize the HTML SparkReporter, and ExtentTestManager using ThreadLocal<ExtentTest> to manage concurrent test threads.
Java (ExtentManager.java & ExtentTestManager.java Thread Safety)
package com.nikita.restassured.reports.extent;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;

import java.io.File;

// ==============================================================================
// 1. GLOBAL EXTENTREPORTS SINGLETON ENGINE
// ==============================================================================
public class ExtentManager {

    private static ExtentReports extent;
    private static final String REPORT_PATH = "target/ExtentReports/ExtentReport.html";

    public static synchronized ExtentReports getInstance() {
        if (extent == null) {
            new File("target/ExtentReports").mkdirs();
            ExtentSparkReporter spark = new ExtentSparkReporter(REPORT_PATH);

            // Configure dashboard presentation and visual theme
            spark.config().setTheme(Theme.STANDARD);
            spark.config().setDocumentTitle("REST Assured API Automation Dashboard");
            spark.config().setReportName("Enterprise Microservices Regression Suite");
            spark.config().setTimeStampFormat("MMM dd, yyyy HH:mm:ss");

            extent = new ExtentReports();
            extent.attachReporter(spark);

            // Inject global environment metadata into report dashboard
            extent.setSystemInfo("Target Stage", System.getProperty("env", "staging").toUpperCase());
            extent.setSystemInfo("Base URL", "https://staging-api.nikita-infotech.com/v1");
            extent.setSystemInfo("Java Runtime", System.getProperty("java.version"));
            extent.setSystemInfo("Execution Engine", "REST Assured + TestNG Parallel");
            extent.setSystemInfo("Author", "Nikita Sharma");

            System.out.println("[*] ExtentManager initialized: Output bound to " + REPORT_PATH);
        }
        return extent;
    }
}

// ==============================================================================
// 2. THREAD-LOCAL TEST INSTANCE MANAGER
// ==============================================================================
class ExtentTestManager {

    private static final ThreadLocal<ExtentTest> testThreadLocal = new ThreadLocal<>();

    public static ExtentTest getTest() {
        return testThreadLocal.get();
    }

    public static void setTest(ExtentTest test) {
        testThreadLocal.set(test);
    }

    public static void removeTest() {
        testThreadLocal.remove();
    }
}
Thread Safety Telemetry: [*] ExtentManager initialized: Output bound to target/ExtentReports/ExtentReport.html System Info Bound: Target Stage: STAGING, Engine: REST Assured + TestNG Parallel Each worker thread retrieves its dedicated ExtentTest via ExtentTestManager.getTest().
Real-Time Example 3: TestNG ITestListener Implementation for Automated Report Hooking
Connecting TestNG lifecycle events to ExtentReports. Implements ITestListener to automatically spawn tests on start, log pass/fail statuses, record throwables on failures, flush reports on completion, and clean up thread memory.
Java (ExtentTestNgListener.java Event Lifecycle Hook)
package com.nikita.restassured.reports.extent;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class ExtentTestNgListener implements ITestListener {

    private static final ExtentReports extent = ExtentManager.getInstance();

    @Override
    public void onTestStart(ITestResult result) {
        String testName = result.getMethod().getMethodName();
        String description = result.getMethod().getDescription();

        // Spawn test under thread-isolated storage
        ExtentTest test = extent.createTest(testName, description);
        ExtentTestManager.setTest(test);

        // Assign category groups if specified on test
        String[] groups = result.getMethod().getGroups();
        for (String group : groups) {
            test.assignCategory(group);
        }

        test.log(Status.INFO, "Started execution of test: " + testName);
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        ExtentTest test = ExtentTestManager.getTest();
        if (test != null) {
            test.log(Status.PASS, MarkupHelper.createLabel("TEST PASSED: " + result.getName(), ExtentColor.GREEN));
        }
        ExtentTestManager.removeTest();
    }

    @Override
    public void onTestFailure(ITestResult result) {
        ExtentTest test = ExtentTestManager.getTest();
        if (test != null) {
            test.log(Status.FAIL, MarkupHelper.createLabel("TEST FAILED: " + result.getName(), ExtentColor.RED));
            // Log root-cause exception stack trace directly to report
            test.fail(result.getThrowable());
        }
        ExtentTestManager.removeTest();
    }

    @Override
    public void onTestSkipped(ITestResult result) {
        ExtentTest test = ExtentTestManager.getTest();
        if (test != null) {
            test.log(Status.SKIP, MarkupHelper.createLabel("TEST SKIPPED: " + result.getName(), ExtentColor.ORANGE));
        }
        ExtentTestManager.removeTest();
    }

    @Override
    public void onFinish(ITestContext context) {
        // Crucial: Flushes all buffered test logs to physical HTML file on disk
        if (extent != null) {
            extent.flush();
            System.out.println("[*] ExtentReports: Flushed test execution dashboard to disk.");
        }
    }
}
Listener Hook Telemetry: onTestStart ──► Creates ExtentTest node and stores in ThreadLocal onTestSuccess ──► Appends green PASS label, cleans up ThreadLocal onTestFailure ──► Appends red FAIL label, embeds stack trace, cleans up ThreadLocal onFinish ──► Calls extent.flush() to compile standalone HTML file
Real-Time Example 4: Pretty-Printing JSON Payloads via MarkupHelper.createCodeBlock()
Embedding formatted wire traffic directly into test logs. Demonstrates using MarkupHelper.createCodeBlock(payload, CodeLanguage.JSON) to display formatted, syntax-highlighted request and response bodies in the HTML report.
Java (ExtentReportUtils.java Payload Markup Formatter)
package com.nikita.restassured.reports.extent;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.CodeLanguage;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import io.restassured.response.Response;

import java.util.Map;

public class ExtentReportUtils {

    /**
     * Logs outgoing HTTP request details with code-block formatting
     */
    public static void logRequestDetails(String method, String endpoint, String jsonBody, Map<String, String> headers) {
        ExtentTest test = ExtentTestManager.getTest();
        if (test == null) return;

        test.log(Status.INFO, MarkupHelper.createLabel("HTTP METHOD: " + method + " | URL: " + endpoint, ExtentColor.BLUE));

        if (headers != null && !headers.isEmpty()) {
            String[][] headerMatrix = headers.entrySet().stream()
                    .map(e -> new String[]{e.getKey(), e.getValue()})
                    .toArray(String[][]::new);
            test.info(MarkupHelper.createTable(headerMatrix));
        }

        if (jsonBody != null && !jsonBody.trim().isEmpty()) {
            test.info("Outbound Request Payload:");
            test.info(MarkupHelper.createCodeBlock(jsonBody, CodeLanguage.JSON));
        }
    }

    /**
     * Logs incoming HTTP response details with status badges and code-block formatting
     */
    public static void logResponseDetails(Response response) {
        ExtentTest test = ExtentTestManager.getTest();
        if (test == null) return;

        int statusCode = response.getStatusCode();
        ExtentColor badgeColor = (statusCode >= 200 && statusCode < 300) ? ExtentColor.GREEN : ExtentColor.RED;

        test.log(Status.INFO, MarkupHelper.createLabel("RESPONSE STATUS: HTTP " + statusCode + " (" + response.getTime() + " ms)", badgeColor));
        test.info("Inbound Response Body:");
        test.info(MarkupHelper.createCodeBlock(response.getBody().asPrettyString(), CodeLanguage.JSON));
    }
}
Dashboard Markup Formatting: - Outbound headers rendered as clean, structured HTML tables. - Outbound JSON bodies formatted inside collapsible <pre><code> blocks. - Inbound response payloads pretty-printed with status code color badges.
Real-Time Example 5: Custom REST Assured Filter for Automated Extent Logging
Building a non-intrusive REST Assured Filter. Intercepts outbound requests and inbound responses, automatically formatting and logging wire traffic to ExtentTestManager without adding manual logging statements in test methods.
Java (ExtentLoggingFilter.java Automatic Wire Interceptor)
package com.nikita.restassured.reports.extent;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.CodeLanguage;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import io.restassured.filter.Filter;
import io.restassured.filter.FilterContext;
import io.restassured.response.Response;
import io.restassured.specification.FilterableRequestSpecification;
import io.restassured.specification.FilterableResponseSpecification;

public class ExtentLoggingFilter implements Filter {

    @Override
    public Response filter(FilterableRequestSpecification requestSpec,
                           FilterableResponseSpecification responseSpec,
                           FilterContext ctx) {

        ExtentTest test = ExtentTestManager.getTest();

        // 1. Intercept and log request before network round-trip
        if (test != null) {
            test.log(Status.INFO, MarkupHelper.createLabel("REQUEST: " + requestSpec.getMethod() + " " + requestSpec.getURI(), ExtentColor.BLUE));

            if (requestSpec.getBody() != null) {
                test.info("Request Body:");
                test.info(MarkupHelper.createCodeBlock(requestSpec.getBody().toString(), CodeLanguage.JSON));
            }
        }

        // 2. Transmit call over network socket
        Response response = ctx.next(requestSpec, responseSpec);

        // 3. Intercept and log response upon return
        if (test != null) {
            ExtentColor statusColor = (response.getStatusCode() >= 200 && response.getStatusCode() < 300)
                    ? ExtentColor.GREEN : ExtentColor.RED;

            test.log(Status.INFO, MarkupHelper.createLabel("RESPONSE: HTTP " + response.getStatusCode() 
                    + " [Latency: " + response.getTime() + " ms]", statusColor));

            if (response.getBody() != null && !response.getBody().asString().isEmpty()) {
                test.info("Response Payload:");
                test.info(MarkupHelper.createCodeBlock(response.getBody().asPrettyString(), CodeLanguage.JSON));
            }
        }

        return response;
    }
}
Filter Integration Standard: Attaching ExtentLoggingFilter to your base RequestSpecification captures every HTTP wire transaction automatically. Test scripts stay clean and focused strictly on API business assertions.
Real-Time Example 6: End-to-End Test Execution with Extent Logging Filter
A complete test implementation demonstrating the Extent logging filter in action. Executes positive registration and negative boundary tests, displaying automatic payload formatting in the resulting report.
Java (ExtentReportedTest.java Clean Test Case Execution)
package com.nikita.restassured.reports.extent;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

// Register Extent TestNG listener for automatic reporting
@Listeners(ExtentTestNgListener.class)
public class ExtentReportedTest {

    private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
    private RequestSpecification spec;

    @BeforeClass
    public void setupSpecification() {
        spec = new RequestSpecBuilder()
                .setBaseUri(BASE_URI)
                .setContentType(ContentType.JSON)
                .setAccept(ContentType.JSON)
                // Attach custom ExtentLoggingFilter for automatic wire capture:
                .addFilter(new ExtentLoggingFilter())
                .build();
    }

    @Test(description = "Verify successful student registration with automatic ExtentReports payload logging",
          groups = {"Smoke", "Regression"})
    public void testStudentRegistrationExtentLogging() {
        Map<String, Object> payload = new HashMap<>();
        payload.put("studentId", "STU-88219");
        payload.put("fullName", "Nikita Sharma");
        payload.put("academicTrack", "ENTERPRISE_AUTOMATION");
        payload.put("enrolledCredits", 16);

        given()
            .spec(spec)
            .body(payload)
        .when()
            .post("/students")
        .then()
            .statusCode(201)
            .body("status", equalTo("SUCCESS"))
            .body("data.id", equalTo("STU-88219"));

        System.out.println("[βœ”] Registration verified. ExtentReports captured wire traffic automatically.");
    }

    @Test(description = "Verify negative boundary validation is documented with Extent failure labels",
          groups = {"Regression"})
    public void testNegativeBoundaryCredits() {
        Map<String, Object> invalidPayload = new HashMap<>();
        invalidPayload.put("studentId", "STU-88220");
        invalidPayload.put("enrolledCredits", 0); // 0 credits triggers validation failure

        given()
            .spec(spec)
            .body(invalidPayload)
        .when()
            .post("/students")
        .then()
            .statusCode(422)
            .body("error", equalTo("CREDITS_BELOW_MINIMUM"));

        System.out.println("[βœ”] Negative boundary condition logged to Extent report.");
    }
}
Console Execution Output: [βœ”] Registration verified. ExtentReports captured wire traffic automatically. [βœ”] Negative boundary condition logged to Extent report. [*] ExtentReports: Flushed test execution dashboard to disk. Report compiled: target/ExtentReports/ExtentReport.html
Real-Time Example 7: Parallel Suite Execution with Thread-Safe Extent Logging
Running concurrent test suites with ExtentReports. Demonstrates configuring a multi-threaded TestNG XML suite (parallel="methods") and executing tests concurrently while confirming that test logs remain strictly isolated.
XML (src/test/resources/testng-extent-parallel.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="ExtentParallelTestSuite" parallel="methods" thread-count="4" verbose="2">

    <listeners>
        <listener class-name="com.nikita.restassured.reports.extent.ExtentTestNgListener"/>
    </listeners>

    <test name="ExtentReportedTests" preserve-order="false">
        <classes>
            <class name="com.nikita.restassured.reports.extent.ExtentReportedTest"/>
        </classes>
    </test>

</suite>
Parallel Execution Telemetry (4 Worker Threads): [Thread-24] ExtentTest started: testStudentRegistrationExtentLogging [Thread-25] ExtentTest started: testNegativeBoundaryCredits [Thread-24] Logged request payload (STU-88219) via ThreadLocal test instance [Thread-25] Logged request payload (STU-88220) via ThreadLocal test instance [Thread-24] Logged response HTTP 201 (210ms) [Thread-25] Logged response HTTP 422 (94ms) Zero log contamination: Each thread writes exclusively to its dedicated test card in the dashboard.
Real-Time Example 8: Debugging NullPointerExceptions & Overwritten Logs Triage
Troubleshooting common ExtentReports integration issues: fixing NullPointerException on ExtentTestManager.getTest(), preventing overwritten logs in parallel suites, and resolving missing extent.flush() calls.
Java (Triage: Diagnosing ThreadLocal NPEs & Missing Flush Defenses)
package com.nikita.restassured.reports.extent;

import org.testng.Assert;
import org.testng.annotations.Test;

public class ExtentTriageTest {

    // ==========================================================================
    // PITFALL 1: NullPointerException ON ExtentTestManager.getTest()
    // Symptom: Calling ExtentTestManager.getTest().info(...) throws NullPointerException!
    //
    // CAUSE: The test class did not register ExtentTestNgListener!
    // As a result, onTestStart() never fired, leaving the ThreadLocal empty.
    //
    // FIX: Always register the listener via @Listeners(ExtentTestNgListener.class)
    // or globally inside the testng.xml  tag!
    // ==========================================================================

    @Test(description = "Verify defensive null handling prevents NPE when listener is missing")
    public void testDefensiveNullCheck() {
        // Defensive check pattern:
        var test = ExtentTestManager.getTest();
        if (test != null) {
            test.info("Safe log message");
        } else {
            System.out.println("[*] Defensive Guard: ExtentTest is null for this thread (Listener not attached). Skipped log.");
        }

        Assert.assertTrue(true);
    }

    // ==========================================================================
    // PITFALL 2: EMPTY REPORT FILE (0 BYTES) AFTER TEST EXECUTION
    // Symptom: target/ExtentReports/ExtentReport.html is completely empty or missing!
    //
    // CAUSE: extent.flush() was never called!
    // ExtentReports buffers all logs in memory and writes to disk only when
    // flush() is executed.
    //
    // FIX: Ensure onFinish() in ITestListener calls extent.flush() unconditionally!
    // ==========================================================================
}
Triage Diagnostic Breakdown: - Problem: NullPointerException when logging wire traffic. - Root Cause: Listener omitted on test class; ThreadLocal was uninitialized. - Fix Applied: Registered ExtentTestNgListener in testng.xml and added defensive null checks in filter. - Result: Clean, failure-free logging across all test threads.
Real-Time Example 9: ExtentReports Specification Reference Matrix
A comprehensive reference summary pairing ExtentReports classes, methods, markup helpers, and operational best practices for REST Assured automation architects.
ExtentReports 5.x Specification Reference Matrix
EXTENTREPORTS 5.x SPECIFICATION REFERENCE MATRIX:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EXTENT CONSTRUCT        β”‚ SYNTAX / API METHOD          β”‚ PARAMETER TYPE   β”‚ PRIMARY OPERATIONAL PURPOSE   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ExtentSparkReporter     β”‚ new ExtentSparkReporter(path)β”‚ File Path String β”‚ Binds output HTML destination β”‚
β”‚ ExtentReports Engine    β”‚ extent.attachReporter(spark) β”‚ Reporter Instanceβ”‚ Core reporting engine instanceβ”‚
β”‚ System Info Injection   β”‚ extent.setSystemInfo(k, v)   β”‚ String Key/Value β”‚ Displays environment metadata β”‚
β”‚ ThreadLocal Container   β”‚ ThreadLocal<ExtentTest>      β”‚ ExtentTest Objectβ”‚ Isolates logs per test thread β”‚
β”‚ createTest              β”‚ extent.createTest(name, desc)β”‚ String, String   β”‚ Spawns individual test entry  β”‚
β”‚ assignCategory          β”‚ test.assignCategory("Smoke") β”‚ String Category  β”‚ Tags tests for group filteringβ”‚
β”‚ Markup CodeBlock        β”‚ MarkupHelper.createCodeBlock β”‚ JSON / XML Stringβ”‚ Pretty-prints wire payloads   β”‚
β”‚ Markup Label            β”‚ MarkupHelper.createLabel(..) β”‚ String, Color    β”‚ Badges status codes / results β”‚
β”‚ Markup Table            β”‚ MarkupHelper.createTable(m)  β”‚ String[][] Matrixβ”‚ Formats request/resp headers  β”‚
β”‚ Throwable Logging       β”‚ test.fail(throwable)         β”‚ Throwable Object β”‚ Embeds exception stack traces β”‚
β”‚ Filter Interceptor      β”‚ ExtentLoggingFilter          β”‚ REST Assured Fltrβ”‚ Automatically logs wire trafficβ”‚
β”‚ Flush Engine            β”‚ extent.flush()               β”‚ Lifecycle Hook   β”‚ Writes buffered logs to disk  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ TOP 5 EXTENTREPORTS BEST PRACTICES:                                                                       β”‚
β”‚ 1. Always use ThreadLocal<ExtentTest>: Prevent log collisions during parallel TestNG executions.          β”‚
β”‚ 2. Embed payloads via MarkupHelper.createCodeBlock(): Keep JSON payloads syntax-highlighted in the UI.    β”‚
β”‚ 3. Always call extent.flush() in onFinish(): Ensure all buffered report data is written to disk.          β”‚
β”‚ 4. Attach ExtentLoggingFilter to RequestSpecBuilder: Log wire exchanges without cluttering tests.         β”‚
β”‚ 5. Populate extent.setSystemInfo(): Display target environment, base URL, and build number on the UI.     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Engineering Best Practice: ExtentReports 5.x provides standalone, executive-ready HTML dashboards for REST Assured test suites. By combining ThreadLocal<ExtentTest> state isolation, ExtentLoggingFilter wire interception, and MarkupHelper JSON formatting inside TestNG listeners, you build clean, self-contained reports that can be distributed and reviewed without running separate reporting servers.