I have recently converted my project from JUnit5 to TestNG, solely for the purpose of getting decent reports.
I have added a listener that generates the report at the end of each run:
@Override
public void onFinish(ITestContext context) {
System.out.println("FINISH. Sending email report.");
utils.EmailHandler.sendEmail("Finished test", context.toString());
}
My problem is that the reports being sent by email are not from the current run, as desired, but the previous run.
Yet if I open the report in /test-output/custom-report.html using Eclipse IDE it is the correct one!
How do I ensure the emails sent out are current?
I have looked at a couple of similar questions here, but neither are appropriate to me:
Similar questions:
TestNg emailable-report is not updating?
ReportNG HTML report not updating
It finally worked when I moved the call to sendEmail to the end of the GenerateReport method of the listener. That removes all confusion and ensures that that output file is complete before attempting to send it out.