Skip to content

Commit

Permalink
Add setting for retry exception logging (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbabcoc authored Mar 16, 2022
1 parent 82636e0 commit ec18d77
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
profile=java8
version=3.0.7-SNAPSHOT
version=3.0.8-SNAPSHOT
org.gradle.java.installations.auto-detect=false
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=JDK7_HOME,JDK8_HOME,JDK11_HOME
22 changes: 15 additions & 7 deletions src/main/java/com/nordstrom/automation/testng/RetryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,8 @@ public boolean retry(final ITestResult result) {
doRetry = isRetriable(result);

if (doRetry) {
if (logger.isDebugEnabled()) {
logger.debug("### RETRY ### [{}/{}] {}",
invocation.suiteName, invocation.testName, invocation, result.getThrowable());
} else {
logger.warn("### RETRY ### [{}/{}] {}",
invocation.suiteName, invocation.testName, invocation);
}
logger.warn("### RETRY ### [{}/{}] {}", invocation.suiteName, invocation.testName, invocation,
getThrowableToLog(result));
}
}

Expand All @@ -139,4 +134,17 @@ protected boolean isRetriable(final ITestResult result) {
}
return false;
}

/**
* Get the {@link Throwable} to log with the retry notification.
*
* @param result result of test method that's being retried
* @return if exception logging is indicated, the exception that caused the test to fail; otherwise {@code null}
*/
private Throwable getThrowableToLog(ITestResult result) {
if (logger.isDebugEnabled() || config.getBoolean(TestNGSettings.RETRY_MORE_INFO.key())) {
return result.getThrowable();
}
return null;
}
}
38 changes: 34 additions & 4 deletions src/main/java/com/nordstrom/automation/testng/TestNGConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,42 @@ public class TestNGConfig extends SettingsCore<TestNGConfig.TestNGSettings> {
* the {@code testng.properties} file and System property declarations.
*/
public enum TestNGSettings implements SettingsCore.SettingsAPI {
/** name: <b>testng.timeout.test</b> <br> default: {@code null} */
/**
* This setting specifies the global default
* <a href="https://javadoc.io/static/org.testng/testng/7.5/org/testng/annotations/Test.html#timeOut()">
* method timeout</a> in milliseconds.
* <p>
* name: <b>testng.timeout.test</b><br>
* default: {@code null}
*/
TEST_TIMEOUT("testng.timeout.test", null),
/** name: <b>testng.retry.analyzer</b> <br> default: <b>com.nordstrom.automation.testng.RetryManager</b> */

/**
* This setting specifies the fully-qualified class name of the default <b>TestNG</b>
* <a href="https://javadoc.io/static/org.testng/testng/7.5/org/testng/annotations/Test.html#retryAnalyzer()">
* retry analyzer</a>.
* <p>
* name: <b>testng.retry.analyzer</b><br>
* default: <b>{@link com.nordstrom.automation.testng.RetryManager}</b>
*/
RETRY_ANALYZER("testng.retry.analyzer", "com.nordstrom.automation.testng.RetryManager"),
/** name: <b>testng.max.retry</b> <br> default: <b>0</b> */
MAX_RETRY("testng.max.retry", "0");

/**
* This setting specifies the maximum number of times a failed method will be retried.
* <p>
* name: <b>testng.max.retry</b><br>
* default: <b>0</b>
*/
MAX_RETRY("testng.max.retry", "0"),

/**
* This setting specifies whether the exception that caused a test to fail will be logged in the notification
* that the test is being retried.
* <p>
* name: <b>retry.more.info</b><br>
* default: {@code false}
*/
RETRY_MORE_INFO("retry.more.info", "false");

private String propertyName;
private String defaultValue;
Expand Down

0 comments on commit ec18d77

Please sign in to comment.