I am currently using ExtentReport with TestNG to get the results of my test. I am now restricted to using only JUnit so I was wondering how I would convert my current code to have the same functionality without using TestNG
I have seen examples of others using either TestWatcher or RunListener but I am not really sure how to implement it for what I need. Especially being new to everything that I am using
@BeforeTest
public void setup() {
htmlReporter = new ExtentHtmlReporter(new File(fileLocation));
htmlReporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
reports = new ExtentReports();
reports.attachReporter(htmlReporter);
}
@AfterTest
public void cleanup() {
reports.flush();
}
@BeforeMethod
public void register(Method method) {
String testName = method.getName();
testInfo = reports.createTest(testName);
}
@AfterMethod
public void captureStatus(ITestResult result) {
if (result.getStatus() == ITestResult.SUCCESS) {
testInfo.log(Status.PASS, "Test: " + result.getName() + " passed");
} else if (result.getStatus() == ITestResult.FAILURE) {
testInfo.log(Status.PASS, "Test: " + result.getName() + " failed");
testInfo.log(Status.FAIL, "Test FAILURE: " + result.getThrowable());
} else if (result.getStatus() == ITestResult.SKIP) {
testInfo.log(Status.PASS, "Test: " + result.getName() + " skipped");
}
}
`
I would like to repoduce the same results from these functions without the use of ITestResult and the rest of the testNG annotations