NUnit Test Runner - how show stacktrace?

Hi,

I'm new to ReSharper 5.1,

I'm running some NUnit test cases, and I'm having problems with the test runner showing the full stack trace during an exception. i.e. the inner exceptions, etc.

My scenario, something like this:

try

{
    CallMyPrivateMethod()

    // ...

    // Do My tests

}

catch (Exception ex)

{

   Assert.Fail(ex.Message);

}

Background 1:

The only reason why I have this try/catch block is because when I do get an exception, I can debug and view the contents of the inner exception.

Background 2:

However, the main issue is that ReSharper isn't showing me the inner exception!

e.g. if I have an exception in CallMyPrivateMethod(), I should be able to see the stack trace and jump to that line of code.

As it is now, if my test case fails, I am forced to debug the test in order to find out where the problem is. Very annoying.

Am I missing something, or does ReSharper just not display the information?

2 comments

Hello Raymond,

This happens because Assert.Fail throws it's own exception that knows nothing
about the inner exceptions of 'ex'. You can use 'throw' statement instead
of Assert.Fail:

try
{
CallMyPrivateMethod()
// ...
// Do My tests
}
catch (Exception ex)
{
    throw;
}

This way you can still view the exception in debugger (by placing a breakpoint
on the 'throw;' line) and also pass that exception up to unit test runner
correctly.


Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hi,
I'm new to ReSharper 5.1,
I'm running some NUnit test cases, and I'm having problems with the
test runner showing the full stack trace during an exception. i.e. the
inner exceptions, etc.
My scenario, something like this:
try
{
CallMyPrivateMethod()
// ...
// Do My tests
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
Background 1:
The only reason why I have this try/catch block is because when I do
get an exception, I can debug and view the contents of the inner
exception.
Background 2:

However, the main issue is that ReSharper isn't showing me the inner
exception!

e.g. if I have an exception in CallMyPrivateMethod(), I should be able
to see the stack trace and jump to that line of code.

As it is now, if my test case fails, I am forced to debug the test in
order to find out where the problem is. Very annoying.

Am I missing something, or does ReSharper just not display the
information?

---
Original message URL:
http://devnet.jetbrains.net/message/5281682#5281682



0

That still doesn't work... the whole point is I need to know where in code the failure is occuring. For now, my only workaround is to do something like this, Assert.Fail (ex.Message + "\r\n" + ex.StackTrace);.

I've used o ther test runners, and I don't recall this being an issue, so I'm pretty sure this is a Resharper (lack-of) feature?

0

Please sign in to leave a comment.