Debugging in NUnit with Visual Studio 2005

Posted by Adrian O'Connor Mon, 01 Oct 2007 16:09:00 GMT

You already know that the debugger is one of the best tools in the entire Visual Studio package. You might not be aware that it is possible to debug your source code when it is running in NUnit (and other code-hosting applications).

To debug your project, follow these simple instructions:

Make sure that Visual Studio 2005 and NUnit are both loaded and that you have opened your project in each.

In Visual Studio, select “Attach to Process” on the Debug menu. Because NUnit is running, you will see nunit.exe in the list of processes. Double click on it.

That’s literally it! Now you can set break-points in your test code (and any code that your test code references), and step through it just as you would if it were running in Visual Studio.

There is one thing to note: when you are compiling and testing in regular and small steps, you might find that things get ‘out of sync’. The first you know about it is likely that Visual Studio tells you that it “can’t find the code for the current location” (sorry, the exact error message slips my memory right now, and I can’t recreate it).

When this happens, close NUnit. If you have the options available, I also suggest running a ‘Clean Solution’ and ‘Rebuild Solution’ before re-loading NUnit. That always fixes the problem, at least for a while.

Comments

Leave a response

Comments