Skip to content

Instantly share code, notes, and snippets.

@poliarush
Created September 3, 2012 08:46
Show Gist options
  • Save poliarush/3607951 to your computer and use it in GitHub Desktop.
Save poliarush/3607951 to your computer and use it in GitHub Desktop.
@Override
public void onTestFailure(ITestResult iTestResult) {
try {
Object testCase = iTestResult.getInstance();
Method testMethod = iTestResult.getMethod().getConstructorOrMethod().getMethod();
logger.error("Fail: " + testMethod.getName(), iTestResult.getThrowable());
invokeAnnotatedMethods(testCase, testMethod, AfterTestFailure.class);
} catch (Exception e) {
logger.error(e);
}
}
private static void invokeAnnotatedMethods(Object testCase, Method testMethod, Class<? extends Annotation> annotation) throws InvocationTargetException, IllegalAccessException {
Method[] methods = testCase.getClass().getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(annotation)) {
method.setAccessible(true);
method.invoke(testCase, testMethod);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment