Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Created Issue: ShouldNotThrow hides stack trace of thrown exception [12473]

$
0
0
When an assertion of the `ShouldNotThrow` family of extension methods fails, the specifics of where in the SUT the exception was thrown is lost. This makes it hard to diagnose because you either need to attach a debugger, or remove the assertion to get the information needed to fix the issue.

Consider the following code (assume it is in a TestFixture):

[Test]
public void This_Should_Not_Throw()
{
Action act = ThrowException;
act.ShouldNotThrow();
}

private void ThrowException()
{
throw new Exception();
}

The failure message is:

>> Did not expect any exception, but found a System.Exception with message "Exception of type 'System.Exception' was thrown.".

and the stack trace shows only `This_Should_Not_Throw` followed by Fluent Assertion code.

If I replace the Fluent Assertion with NUnit's Assert.DoesNotThrow(new TestDelegate(act)), the stack trace is equally unhelpful; however I get this message:

>> Expected: No Exception to be thrown
But was: (Exception of type 'System.Exception' was thrown.)
at ExceptionTest.Class1.ThrowException() in c:\Users\adamv\Documents\Visual Studio 11\Projects\ExceptionTest\ExceptionTest\Class1.cs:line 21
at NUnit.Framework.Constraints.ThrowsNothingConstraint.Matches(Object actual)

If I simply take out the assertion and execute the delegate, I get a complete stack trace.

I would expect Fluent Assertions to provide the stack trace as part of the message in a way similar NUnit. Without this functionality it is better to use the NUnit assertion or use no assertion at all.

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>