assertj: Describe actual Throwables when ThrowableAssert fails
Summary
When some Throwable
-related assertion fails the actual Throwable
that failed the check is not described beyond what actually caused assertion failure (e.g. message mismatch). In non-trivial code when unexpected Exception
s are thrown this makes debugging inconvenient.
Dumping more comprehensive (class, message, stack, perhaps even recursive info about causes) info about the actual Throwable
could ease assertion failure investigation.
Relevant message factories (e.g. ShouldHaveMessage
) already have access to actual Throwable
.
It may be tempting to use util.Throwables.ERROR_DESCRIPTION_EXTRACTOR
to describe throwables, but a more powerful mechanism would be appreciated.
Providing precise information in case of assertion failure doesn’t seem to be overkill (unlike as in #864)
Error message to improve
- ShouldHaveCause #2872
- ShouldHaveCauseExactlyInstance
- ShouldHaveCauseInstance
- ShouldHaveCauseReference - @weiyilei
- ShouldHaveNoCause
- ShouldHaveNoSuppressedExceptions
- ShouldHaveRootCauseExactlyInstance #2910
- ShouldHaveRootCauseInstance #2910
- ShouldHaveSuppressedException
- ShouldNotContainCharSequence
- ShouldStartWith
- ShouldEndWith
If you are interested in contributing to this issue, select one error message, it will be assigned to you.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 22 (12 by maintainers)
Commits related to this issue
- Show the stack trace for the Throwable under test when hasMessageMatching fails (#1355) — committed to assertj/assertj by steveorourke 5 years ago
- Show the stack trace for the Throwable under test when hasMessageFindingMatch fails (#1355) — committed to assertj/assertj by steveorourke 5 years ago
Hi @joel-costigliola I created a PR to update the ShouldHaveCause with Stacktrace. Please let me know if there is a problem.
Hi, I’ve created a PR fixing the
hasCauseInstanceOf
andhasCauseExactlyInstanceOf
. Please let me know if there is any problem:-).Submitted #1630 to do the same for
hasMessageMatching
andhasMessageFindingMatch
assertions.