开发者

How to debug unittest failures in Visual C# 2008?

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开发者_StackOverflow 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?


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".


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜