'How to combine ExtentReports for multiple JUnit5 test classes into one HTML file?

I'm using ExtentReports (version 5.0.5) with JUnit 5. Here is my BaseTest class snippet.

public class BaseTest
{
    protected static ExtentReports extent;
    protected ExtentTest test;
    protected ExtentTest node;

    @BeforeAll
    static void oneTimeSetup()
    {
        extent = new ExtentReports();
        ExtentSparkReporter spark = new ExtentSparkReporter(
                "target/results" + TimestampGenerator.currentTimestamp() + ".html");
        extent.attachReporter(spark);
    }

    @AfterAll
    static void oneTimeTearDown() throws Exception
    {
        extent.flush();
    }
}

I have 2 test classes in the suite. If I do not use the timestamp in the report name, the program creates one report for the last test class. That's why I added the timestamp. Now when I run the suite in Eclipse, it creates 2 HTML reports for each test class in the suite.

enter image description here

How can I have only one file that contains info for both test classes?



Solution 1:[1]

You can write a separate class which will read the contents of both reports and create a new HTML report with contents of both files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 O_K