views:

38

answers:

2

Hopefully a nice n simple one for you

Running some tests in VS2010's testing framework. When an exception is thrown somewhere inside it, the results screen shows nothing of the details.

Simplest example:

[TestMethod]
public void DoTest()
{
    int y = 10 - 10;
    int x = 10 / y;
}

Test method MyProj.DoTest threw exception: ...

You can't see it here, but before the '...' there is some sort of special hidden character (displays as a square). How can I view the details, and ideally, the stacktrace.

A: 

I would trace through the test code using the debugger until you find the line where the exception is being thrown. That will help you narrow it down.

Bill W
That's what I am doing now.Is there no other way? seems pretty poor on MS's part. NUnit would always give you a full stack trace on a failed test.And now, even when I find the line, I can't see why it is failing, I have to edit the code to put a try/catch around the failing line to be able to see anything of what is causing it to fail.
jb
+2  A: 

Actually, you don't have to add try/catch blocks. If you simply click Debug instead of Run:

alt text

it will automatically break there and show you the type of exception: alt text

You must also make sure to go to Debug -> Exceptions (Ctrl+Alt+E) and go to Common Language Runtime Exceptions->System->ystem.DivideByZero exception is either Thrown, or User-andled. If neither of those are checked, nothing will be shown as you debug, and you will get what you described. This, of course, is true for all exceptions.

sbenderli