Monday, 17 September 2018

TestNg | Rerun a failed test case ; Amazon interview qn

Option# 1. testng-failed.xml file in test-output directly
when we run any test suite tesng generates testng-failed.xml file if any failure happens. Just go there and right click on it and Run it.

Option#2 IRetryAnalyzer

public class Retry implements IRetryAnalyzer{
int count =0, retryCount = 3;
   public boolean retry(ITestResult result){
       if(count<retryCount){
           count++;
           return true;
         }
    }
}

In Test file
@Test(retryAnalizer=Retry.class)
public void m1(){
}


Option#3: IAnnotationTransformer
a. Use the same Retry class here

b. public class Transformation implement IAnnotationTrnasformer
{
          @Override
          public void transform(ITestAnnotation annotation, Class testClass, Constructor                    testConstructor,Method test method){
           IRetryAnalyzer  retry = annotation.getRetryAnalyzer();
            if(retry == null){
            annoatation.setRetryAnalyzer(Retry.class);
                 }
           }
}
c. add a listener
<listeners>
<listener class-name="com.google.Transformation">
</listners>

No comments:

Post a Comment