Just another programmer's site.

Debugging code called while NUnit testing.

This post is intended mostly as a reminder for myself.This is probably a beaten path so I expect a lot of people already know how to do this if they need.

Let’s say you are executing your NUnit tests using the NUnit console.Something is happening and you want to be able to stop at a breakpoint somewhere in the code that you are testing.So, while you have your NUnit console executable up and running, in Visual Studio go to Tools\Attach to Process ….This will open a dialog where you can select the process you want to attach to. This is : “nunit-agent.exe” and after you selected it click Attach. (Leave all the other setting settings to their default values: Transport=Default, Qualifier=<your_computer_name>, Attach to=Automatic)

We will assume the dialog was dismissed cleanly with no errors and you are back to the main VS window. At this point, if you have a breakpoint in your to be tested code, switch to NUnit console and just Run (or Run All) tests. Of course the portion of the tested code with a breakpoint in it has to be called eventually (directly or indirectly) from the testing code. If that is the case, the execution will now stop at that breakpoint allowing you to go step by step, investigate the values of variables and so on.