shouldly / shouldly

Should testing for .NET—the way assertions should be!

Home Page:https://docs.shouldly.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShouldThrow<T>() assertion failure message not very helpful

yinzara opened this issue · comments

When using the Should.Throw<T>() or aTask.ShouldThrowAsync<T>(), if an exception is thrown but is of a different type from the expected exception, the message prints:

Shouldly.ShouldAssertException : Task `await Should`
    should throw
  TExpectedException
    but threw
  TActualException

Usually when this happens, it's because some unexpected exception happened.

However, it's extremely difficult to debug this because the failure doesn't actually print the message from the wrong exception.

To debug, I actually have to change it to var exp = aTask.ShouldThrow<Exception>(); so I can actually read the message.

I'm requesting a feature enhancement to the formatting of this failure message to also include the "Message" property of the exception that was thrown.