Last active
November 14, 2017 07:05
-
-
Save LenarBad/47d0514f65c59916583d09830df1aace to your computer and use it in GitHub Desktop.
How to re-run failed tests in TestNG using IRetryAnalyzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.DateTime; | |
import org.testng.IRetryAnalyzer; | |
import org.testng.ITestResult; | |
public class RetryAnalyzer implements IRetryAnalyzer { | |
private int retryCount = 0; | |
private static int maxNumberOfRetriesForUnstableTests = 2; | |
private static int maxNumberOfRetriesForVeryUnstableTests = 3; | |
private static int relaxDayMaxNumberOfRetries = 10; | |
private static String rushDay = "Monday"; | |
private static String relaxDay = "Thursday"; | |
public boolean retry(ITestResult result) { | |
retryCount++; | |
if (isRushDayToday()) return false; | |
if (isRelaxDayToday() && retryCount <= relaxDayMaxNumberOfRetries) return true; | |
if (retryCount <= maxNumberOfRetriesForVeryUnstableTests && result.getName().equals("veryUnstableTest")) return true; | |
if (retryCount <= maxNumberOfRetriesForUnstableTests) return true; | |
return false; | |
} | |
private boolean isRushDayToday() { | |
return new DateTime().dayOfWeek().getAsText().equals(rushDay); | |
} | |
private boolean isRelaxDayToday() { | |
return new DateTime().dayOfWeek().getAsText().equals(relaxDay); | |
} | |
} | |
import org.testng.annotations.Test; | |
public class RetryExampleTest { | |
@Test | |
public void stableTest() { | |
// some test code | |
} | |
@Test(retryAnalyzer = RetryAnalyzer.class) | |
public void unstableTest() { | |
// some test code | |
} | |
@Test(retryAnalyzer = RetryAnalyzer.class) | |
public void veryUnstableTest() { | |
// some test code | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.testng.annotations.Test; | |
public class RetryExampleTest { | |
@Test | |
public void stableTest() { | |
// some test code | |
} | |
@Test(retryAnalyzer = RetryAnalyzer.class) | |
public void unstableTest() { | |
// some test code | |
} | |
@Test(retryAnalyzer = RetryAnalyzer.class) | |
public void veryUnstableTest() { | |
// some test code | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to re-run failed tests in TestNG