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 t开发者_开发知识库o identify root issue.
How can i tackle this?
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.
I doubt it really answers your question, but I'd shorten the test to a single situation so that you don't need to wrap some code into a delegate that you pass to Assert.DoesNotThrow
. Then, just write the test without any assertions. A test that throws an unexpected exception will fail, so it will do what you want, and you'll get the full exception.
About 10%-ish of my tests work like this; no assertions at all, and method names like ThisOrThatShouldNeverThrow()
.
Another option, while debugging, is to run the test in a debugger (using TD.Net) and in Debug|Exceptions check some additional boxes so that the debugger stops when the exception is thrown.
精彩评论