Search code examples
javaunit-testingreportingjersey-2.0extentreports

Testing using Jersey framework with reporting using Extentreports


I am new to testing, need to report testing results using extentreports,

below is the code for testing:

public ExtentReports reports;
public ExtentTest logger;

public ModelTests() {
    reports = new ExtentReports("acceptanceTest\\reports\\Report.html");
}

@Test
public void searchModelTest() throws JSONException, URISyntaxException {
    JSONObject jsonResponse = searchModel();                
    logger = reports.startTest("Test");
    logger.log(LogStatus.PASS, "Success");
    assertEquals("SOLAR SLEEVE 2014", jsonResponse.getString("modelName"));
    logger.log(LogStatus.FAIL, "Failure");
    reports.endTest(logger);
}

I do not see any report getting generated.

Will extentreport work with jersey framework, I have seen selenium examples.

Help will be appreciated.


Solution

  • Here is a checklist that you should follow:

    1. Create a new instance of ExtentReports.

      ExtentReports extent = new ExtentReports(file-path, replaceExisting);

    2. Name and describe the instance via the startTest method. Keep in mind, you are now creating a new instance of ExtentTest.

      ExtentTest test = extent.startTest("Test Name", "Sample description");

    3. Log your results against your ExtentTest instance.

      test.log(LogStatus.PASS, "Step details");

    4. End your test.

      extent.endTest(test);

    5. Finally write everything to your document

      extent.flush();

    Also, here is the documentation specifically for those implementing via Maven.

    ExtentReports | Maven Documentation

    ...