Retry Listner retrying passed test cases also and failed retry test is showing as skipped test

806 views
Skip to first unread message

Abhishek Bisht

unread,
Apr 19, 2016, 2:01:53 AM4/19/16
to testng-users
Hi All,

I am using testng 6.9.6 and using retry listener but even passed test are running multiple times and failed tests are appearing as skipped test 

public class RetryListener  implements IAnnotationTransformer 
{

@SuppressWarnings("rawtypes")
@Override
public void transform(ITestAnnotation testannotation, Class testClass,
            Constructor testConstructor, Method testMethod) 
{
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();

if (retry == null) {

testannotation.setRetryAnalyzer(RetryAnalyzer.class);

}

}


Retry class

public class RetryAnalyzer implements IRetryAnalyzer {
public int count = 0;

private int maxCount = 1;

public RetryAnalyzer() {
setCount(maxCount);
}

@Override
public boolean retry(ITestResult result) {

if (!(result.isSuccess())) {
if (count < maxCount) {
count++;
Reporter.log(Thread.currentThread().getName() + " Error in "
+ result.getName() + " with status "
+ result.getStatus() + " Retrying " + count + " times");
return true;
}

}
return false;
}

public void setCount(int count) {
maxCount = count;
}
}

Please help how can i handle and stop passed test from re runnning

Shawn McCarthy

unread,
Apr 19, 2016, 12:15:11 PM4/19/16
to testng-users
Have you tried 6.9.9 or 6.9.10 or 6.9.11 ?

Abhishek Bisht

unread,
Apr 21, 2016, 12:33:28 AM4/21/16
to testng...@googlegroups.com
Yes I have tried with testng 6.9.9 but again eve passed test cases are executed again

Regards
Abhishek Bisht
Contact no.- 9990421145

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

deepak gupta

unread,
Jan 5, 2017, 12:38:43 AM1/5/17
to testng-users
Hi All,

I am using TestNG 6.9.10 and facing  some issue's with  IAnnotationTransformer & IRetryAnalyzer interface's while implementing Retry logic for false failure.

1. Issue is : Suppose I want to retry failed test case two times, While execution its shows like Skip in First & second attempt & then fail.
    But at last its show  something like :
            Run 1: PASS
            Run 2: PASS
            Run 3: ********VerifyRateTableHas20Records:Intentionally fail!!!!!!!!! expected [true] but found [false]   
           and same thing has also been updated in reports as well.

Can someone please help me out???

   My Code :

   public class AnnotationTransformer implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        annotation.setRetryAnalyzer(Retry.class);
    }


public class Retry implements IRetryAnalyzer {

    private int count = 0;
    private static int maxTry = 3;

    @Override
    public boolean retry(ITestResult iTestResult) {
        if (!iTestResult.isSuccess()) {                      //Check if test not succeed
            if (count < maxTry) {                            //Check if maxtry count is reached
                count++;                                     //Increase the maxTry count by 1
                iTestResult.setStatus(ITestResult.FAILURE);  //Mark test as failed
                return true;                                 //Tells TestNG to re-run the test
            } else {
                iTestResult.setStatus(ITestResult.FAILURE);  //If maxCount reached,test marked as failed
            }
        } else {
            iTestResult.setStatus(ITestResult.SUCCESS);      //If test passes, TestNG marks it as passed
        }
        return false;
Reply all
Reply to author
Forward
0 new messages