Search code examples
c#unit-testingnunittestdriven.net

Assert.DoesNotThrow with NUnit -- how to get stack trace?


I am using NUnit for unit testing (running with TD.NET).

When using Assert.DoesNotThrow, i get the exception, but without any stack trace, which makes it harder to identify root issue.

How can i tackle this?


Solution

  • The Assert.DoesNotThrow is redundant, if a tests throws the test will fail automatically without an assert. To clarify what is being tested is, in my humble opinion, better conveyed in the test method name. There is very little documentation benefit in the Assert.DoesNotThrow syntax and, as you point out, just makes it harder to fix failing tests.

    Also, if you have a very long test with multiple asserts the Assert.DoesNotThrow fills an important role as to assert that the correct code block threw an exception. However, in this case a more suitable solution is to see if the test can be shortened and/or asserts moved into their own tests.