retrylogic

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

retrylogic

Kiran-2
Hi,

Question on retry logic for failed tests and following are the class files:

TestRetry class:
public class TestRetry implements IRetryAnalyzer {
int counter=0;
int retryLimit=4;

@Override
public boolean retry(ITestResult result) {
if (counter < retryLimit) {
  TestReporter.logStep("Retrying Test " +result.getName()+" for number of times: "+(counter+1));
  counter++;
          return true;
}
return false;
}

RetryListener class:
public class RetryListener implements IAnnotationTransformer {

@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
// TODO Auto-generated method stub
IRetryAnalyzer retry = annotation.getRetryAnalyzer();

        if (retry == null) {

            annotation.setRetryAnalyzer(TestRetry.class);
}

}}

Test class:

@Listeners(RetryListener.class)
public class RetryLogicTest {
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context) {
   for (ITestNGMethod method : context.getAllTestMethods()) {
          method.setRetryAnalyzer(new TestRetry());
   }
}

@Test(priority=0)
public void firsttest() {
TestReporter.assertEquals("Test", "Test", "pass");
}
@Test(priority=1, dependsOnMethods="firsttest")
public void secondtest() {
TestReporter.assertEquals("Test", "Test1", "fail");
}
@Test(priority=2,dependsOnMethods="secondtest")
public void thirdtest() {
TestReporter.assertEquals("Test", "Test", "pass");

}

when the above RetryLogicTest is run 

results are :
firsttest is passed
secondtest is failed and retried 5 times , on  5th time still it is failed
thirdtest is skipped because it depends on secontest

The above results are working as expected. 

Question
Since the secondtest depends on firsttest, thirdtest depends on secondtest. When one of them fails, I want to execute all the tests from first again. Is there a way to do it?

So any tests fail, I want all the test from first to be executed as it depends on each test.

Thanks!
Kiran



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.