willowtreeapps / assertk

assertions for kotlin inspired by assertj
MIT License
760 stars 85 forks source link

Consider adding actual `Throwable` as cause of `AssertionFailedError` #456

Closed JakeWharton closed 1 year ago

JakeWharton commented 1 year ago

If I do

assertThat { somethingWhichFails() }
  .isFailure()
  .isInstanceOf(IllegalStateException::class)

and something else fails throwing a different error type, all I see is:

expected to be instance of:<class java.lang.IllegalArgumentException> but had class:<class java.lang.AssertionError> (Failure(java.lang.AssertionError))

That isn't helpful!

It's a special casing, but in the case of the "actual" being a Throwable or a Result that's a failure, I think the fail function should add that Throwable as the cause to the AssertionFailedError.

This would provide me with the complete stacktrace of the unexpected failure and not just that the type or message disagrees.

We do this in Turbine and it's excellent. I would like it here, too!

JakeWharton commented 1 year ago

Oh this is worse than I thought. So many do not pass expected or actual to fail including things like isInstanceOf.