Created
September 3, 2012 08:46
-
-
Save poliarush/3607951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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