Skip to content

Commit

Permalink
method for default log for throwables created.
Browse files Browse the repository at this point in the history
Added call in SoftAssert to allow downstream modification of SoftAssert
output
  • Loading branch information
Ryan Laseter committed Jan 3, 2019
1 parent f1111e0 commit a673eed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
New: Added a method in Assertion class to allow downstream TestNG consumers to override the error message (Ryan Laseter)
Fixed: GITHUB-165: @AfterGroups is not executed when group member fails or is skipped (Krishnan Mahadevan)
Fixed: GITHUB-118: @BeforeGroups only called if group is specified explicitly (Krishnan Mahadevan)
Fixed: GITHUB-182: Inherited test methods do not get expected group behavior (Krishnan Mahadevan)
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/testng/asserts/Assertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,21 @@ public void doAssert() {
}
});
}

/***
* Override this method should you want to change
* the default way Throwable objects are logged.
* @param error Throwable of the Assertion
* @return default throwable formatted message for TestNG
*/
protected String getErrorDetails(Throwable error) {
StringBuilder sb = new StringBuilder();
sb.append(error.getMessage());
Throwable cause = error.getCause();
while (cause != null) {
sb.append(" ").append(cause.getMessage());
cause = cause.getCause();
}
return sb.toString();
}
}
7 changes: 1 addition & 6 deletions src/main/java/org/testng/asserts/SoftAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ public void assertAll() {
sb.append(",");
}
sb.append("\n\t");
sb.append(error.getMessage());
Throwable cause = error.getCause();
while (cause != null) {
sb.append(" ").append(cause.getMessage());
cause = cause.getCause();
}
sb.append(getErrorDetails(error));
}
throw new AssertionError(sb.toString());
}
Expand Down

0 comments on commit a673eed

Please sign in to comment.