0
votes

My Junit Test function has try-catch block. In catch block I am catching exception to log error in ExtentReport. Also, I am generating Junit report from Apache ant 'junitreport'. My problem is, since I am catching the exception in my catch block, the Junit result generated does not show error. How to throw exception (or some other way) to register the exception for Junit result also.

Here is the code :

try {
    //Test code
    } catch (Exception e) {
            extentTest.log(LogStatus.ERROR, "Exception in clicking "); //For ExtentREport Logging
            e.printStackTrace();
            throw(new Exception(e.getMessage(), e)); //Expected Junit to capture error, but it is not happening
    }

Screen shot of both Extent Report and Junit report of the same test

1

1 Answers

0
votes

Instead of wrapping the exception you could rethrow it.

try {
    //Test code
} catch (Exception e) {
    extentTest.log(LogStatus.ERROR, "Exception in clicking "); //For ExtentREport Logging
    e.printStackTrace();
    throw e;
}