final Object freshInstance) throws Throwable{
final RunNotifier testRunNotifier = new RunNotifier();
final TestRunDurationListener testRunDurationListener = new TestRunDurationListener();
testRunNotifier.addListener(testRunDurationListener);
final EachTestNotifier eachRunNotifier = new EachTestNotifier(testRunNotifier, null);
String currentMethodName = method.getMethod().getName();
TestResultBean testResult = method.getTestResult();
Map<String, Object> writableRow = method.getTestData();
Object returnObj = null;
try {
final Object[] values = complete.getMethodArguments(true);
testResult.setInput(method.getTestData());
// invoke test method
eachRunNotifier.fireTestStarted();
LOG.debug("Calling method {} with values {}", method.getName(), values);
returnObj = method.invokeExplosively(freshInstance, values);
eachRunNotifier.fireTestFinished();
TestMethodDuration testItemDurationBean = new TestMethodDuration(currentMethodName,
testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano());
testResult.addTestItemDurationBean(testItemDurationBean);
testResult.setOutput((returnObj == null) ? "void" : returnObj);
testResult.setPassed(Boolean.TRUE);
if (writableRow != null) {
if (returnObj != null) {
LOG.debug("Data returned by method {} is {} :", method.getName(), returnObj);
writableRow.put(Loader.ACTUAL_RESULT, returnObj);
Object expectedResult = writableRow.get(Loader.EXPECTED_RESULT);
// if expected result exist in user input test data,
// then compare that with actual output result
// and write the status back to writable map data.
if (expectedResult != null) {
LOG.debug("Expected result exists");
if (expectedResult.toString().equals(returnObj.toString())) {
writableRow.put(Loader.TEST_STATUS, Loader.TEST_PASSED);
} else {
writableRow.put(Loader.TEST_STATUS, Loader.TEST_FAILED);
}
}
}
LOG.debug("testItemDurationBean:" + testItemDurationBean);
if (testItemDurationBean != null) {
Double testDuration = CommonUtils.getRounded(testItemDurationBean.getRoundedMsDifference()
.doubleValue(), 3);
LOG.debug("testItemDurationBean.getRoundedMsDifference():" + testDuration);
writableRow.put(Loader.DURATION, testDuration);
}
}
} catch (AssumptionViolatedException e) {
eachRunNotifier.addFailedAssumption(e);
handleAssumptionViolation(e);
} catch (Throwable e) {
if (e instanceof AssertionError) { // Assertion error
testResult.setPassed(Boolean.FALSE);
testResult.setResult(e.getMessage());
} else { // Exception
testResult.setException(Boolean.TRUE);
testResult.setExceptionResult(e.toString());
}
eachRunNotifier.addFailure(e);
throw e;
} finally {
eachRunNotifier.fireTestFinished();
}
//The test should fail in case the Actual Result returned by the test method did
//not match the Expected result specified for the method in the test data file.
if (writableRow != null && writableRow.get(Loader.TEST_STATUS) != null
&& writableRow.get(Loader.TEST_STATUS).equals(Loader.TEST_FAILED)) {