Skip to content

Commit ec18d77

Browse files
authored
Add setting for retry exception logging (#57)
1 parent 82636e0 commit ec18d77

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
profile=java8
2-
version=3.0.7-SNAPSHOT
2+
version=3.0.8-SNAPSHOT
33
org.gradle.java.installations.auto-detect=false
44
org.gradle.java.installations.auto-download=false
55
org.gradle.java.installations.fromEnv=JDK7_HOME,JDK8_HOME,JDK11_HOME

src/main/java/com/nordstrom/automation/testng/RetryManager.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,8 @@ public boolean retry(final ITestResult result) {
110110
doRetry = isRetriable(result);
111111

112112
if (doRetry) {
113-
if (logger.isDebugEnabled()) {
114-
logger.debug("### RETRY ### [{}/{}] {}",
115-
invocation.suiteName, invocation.testName, invocation, result.getThrowable());
116-
} else {
117-
logger.warn("### RETRY ### [{}/{}] {}",
118-
invocation.suiteName, invocation.testName, invocation);
119-
}
113+
logger.warn("### RETRY ### [{}/{}] {}", invocation.suiteName, invocation.testName, invocation,
114+
getThrowableToLog(result));
120115
}
121116
}
122117

@@ -139,4 +134,17 @@ protected boolean isRetriable(final ITestResult result) {
139134
}
140135
return false;
141136
}
137+
138+
/**
139+
* Get the {@link Throwable} to log with the retry notification.
140+
*
141+
* @param result result of test method that's being retried
142+
* @return if exception logging is indicated, the exception that caused the test to fail; otherwise {@code null}
143+
*/
144+
private Throwable getThrowableToLog(ITestResult result) {
145+
if (logger.isDebugEnabled() || config.getBoolean(TestNGSettings.RETRY_MORE_INFO.key())) {
146+
return result.getThrowable();
147+
}
148+
return null;
149+
}
142150
}

src/main/java/com/nordstrom/automation/testng/TestNGConfig.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,42 @@ public class TestNGConfig extends SettingsCore<TestNGConfig.TestNGSettings> {
3232
* the {@code testng.properties} file and System property declarations.
3333
*/
3434
public enum TestNGSettings implements SettingsCore.SettingsAPI {
35-
/** name: <b>testng.timeout.test</b> <br> default: {@code null} */
35+
/**
36+
* This setting specifies the global default
37+
* <a href="https://javadoc.io/static/org.testng/testng/7.5/org/testng/annotations/Test.html#timeOut()">
38+
* method timeout</a> in milliseconds.
39+
* <p>
40+
* name: <b>testng.timeout.test</b><br>
41+
* default: {@code null}
42+
*/
3643
TEST_TIMEOUT("testng.timeout.test", null),
37-
/** name: <b>testng.retry.analyzer</b> <br> default: <b>com.nordstrom.automation.testng.RetryManager</b> */
44+
45+
/**
46+
* This setting specifies the fully-qualified class name of the default <b>TestNG</b>
47+
* <a href="https://javadoc.io/static/org.testng/testng/7.5/org/testng/annotations/Test.html#retryAnalyzer()">
48+
* retry analyzer</a>.
49+
* <p>
50+
* name: <b>testng.retry.analyzer</b><br>
51+
* default: <b>{@link com.nordstrom.automation.testng.RetryManager}</b>
52+
*/
3853
RETRY_ANALYZER("testng.retry.analyzer", "com.nordstrom.automation.testng.RetryManager"),
39-
/** name: <b>testng.max.retry</b> <br> default: <b>0</b> */
40-
MAX_RETRY("testng.max.retry", "0");
54+
55+
/**
56+
* This setting specifies the maximum number of times a failed method will be retried.
57+
* <p>
58+
* name: <b>testng.max.retry</b><br>
59+
* default: <b>0</b>
60+
*/
61+
MAX_RETRY("testng.max.retry", "0"),
62+
63+
/**
64+
* This setting specifies whether the exception that caused a test to fail will be logged in the notification
65+
* that the test is being retried.
66+
* <p>
67+
* name: <b>retry.more.info</b><br>
68+
* default: {@code false}
69+
*/
70+
RETRY_MORE_INFO("retry.more.info", "false");
4171

4272
private String propertyName;
4373
private String defaultValue;

0 commit comments

Comments
 (0)