Skip to content

Commit

Permalink
Merge pull request testng-team#1984 from Proryanator/master
Browse files Browse the repository at this point in the history
Feature: Make method for error details, that can encourage downstream customization of SoftAssert errors
  • Loading branch information
krmahadevan authored Jan 8, 2019
2 parents f1111e0 + a673eed commit 73a1843
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 73a1843

Please sign in to comment.