I added this functionality to our test framework. No need to add annotation to each method/class. I read a property and based on it i will add retryAnalyzer annotation to tests.
@Override
public void transform(ITestAnnotation annotation,
Class testClass,
Constructor testConstructor,
Method testMethod) {
if ((annotation.getRetryAnalyzer() == null)
&& (RetryAnalyzer.getMaxRerun() > 0)) {
logDebug(
tcID,
"Adding RetryAnalyzer.class to method "
+ testMethod.getName()
+ " as test suite properties has rerun count = "
+ RetryAnalyzer.getMaxRerun()+ " To enable rerun of failed test case");
annotation.setRetryAnalyzer(RetryAnalyzer.class);
}
}
static public int getMaxRerun() {
Integer rerunCount = 0;
String property = EnvironmentSpecificProperty.getProperty(
xxxxxxxx.base.common.Constants.NUMBER_OF_RERUNS,
tcID);
if (!StringUtils.isEmpty(property))
rerunCount = Integer.valueOf(property);
return rerunCount;
}
Hope it helps. Its working fine in our test framework.
Tests just use it as below :- in property file they just add
rerunNum=1
By default no retry. If we see this we retry that many attempts user specified.
For the kicks we have added a configurable sleeptime as well before rerunning tests incase if user want to wait before rerunning tests(OPTIONAL).
like :-
#delay in secs
rerunDelay=1
Thanks
Shankar KC