views:

62

answers:

3

This is nearly my first experience with unit testing.

I added a unittest to my solution, and selected Test->Run->All Tests in Solution. My test failed due to an exception which got thrown in the tested code.

Normally, I would then go to the stacktrace toolwindow, click my way through it, looking at the values of locals in every stackframe, and figure out what went wrong. But when code fails within an unittest, I don't get the normal "yellow balloon" exception notification, and I'm not able to explore the stacktrace in detail. All I get is a "TestMethod1 [Results]" tab, which displays only the exception message and a plaintext stacktrace. So, no access to the values of locals, no access to any debug-output I may have printed to the console...

How am I supposed to debug it then?

+2  A: 

You need to select "Test->Debug->All tests in solution" then the debugger works as normal. All the normal debug windows are available by going to "Debug->Windows".

Matt Breckon
Alright, I did that, but I still don't see the normal stacktrace window, with access to locals etc.
Stefan Monov
To see locals, go to 'Debug' menu, 'Windows' and you should see 'Locals' and 'Stack Trace' appear.
Jason Evans
A: 

Hi there.

You can put a breakpoint in your code, like this:

<TestMethod> _
Public Sub Test()   <--- Put breakpoint here.

and then choose to debug the unit test, you can then step through the code.

Cheers. Jas.

Jason Evans
A: 

You can install TestDriven.NET, which is a Visual Studio add-in that allows you to do just that - debug your tests. There is a free community version.

Mathias