I had the similar requirement. I achieved it. (Extent Report V3 and above)
BaseTest is being extended by all the test class.
Class BaseTest{
Class BaseTest{
public static ExtentReports extent =new ExtentReports();//initiating here is very important
public static ExtentHtmlReporter htmlReporter;
@BeforeSuite
public void beforeSuiteSetup() {
String filepath = System.getProperty("user.dir");
htmlReporter = new ExtentHtmlReporter(filepath+"/Report.html");
extent.attachReporter(htmlReporter);
}
@AfterSuite(alwaysRun = true)
public void afterSuite() {
extent.flush();
}
}