Saturday, 13 October 2012

How to immediate rerun failed testcase using testng.

After developing a automation framework,now a automation tester want to reduce a false positive rate,so he/she will use immediate rerun of failed test case for reducing the failed test due to setup and network problem.

Below is the code for same:

1) Create a class with your rerun logic

Using the below logic you can immediate rerun your failed test case.
package com.companyName.web.utils;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class Retry implements IRetryAnalyzer{
private int retryCount = 0;
private int maxRetryCount = 3;
public boolean retry(ITestResult result) {

if(retryCount < maxRetryCount) { retryCount++; return true; } return false; } }

2) use below annotation in your test program
if you are not using group then use this


  1. Thanks! Good trick to avoid that many false positives!

  2. hi,do you know how to configure this listener in the test suite so i no need to add the annotation in every test ?

  3. it do not work fine in tesng 6.1.1

  4. You can try from here. It is provided with working sample.