When using the NUnit GUI to run unit tests, is there a way to either:
- Set breakpoints inside the tests,
- or break into the Visual Studio Just-in-Time debugger upon failure of a test?
When using the NUnit GUI to run unit tests, is there a way to either:
Attach the Visual Studio debugger to the NUnit process, and then run your tests in the NUnit GUI.
If you attach your Visual Studio debugger to the nunit process and execute your test in nunit, then the breakpoints in Visual Studio will be used.
I'm not aware of how this might be done upon failure of a test.
Your first requirement is very straightforward. Attach the VS debugger to the NUnit GUI (Tools->Attach to Process) and set your breakpoints accordingly. When the tests run with the debugger attached, the breakpoints will be hit.
The second requirement is also straightforward, but I haven't verified it to work (that is, I know it will break, but I don't how far from user-code it will break). When a unit test fails, the NUnit framework raises an NUnit.Framework.AssertionException
. Set the debugger to break when this exception is thrown, and you won't need to set breakpoints in your code. To do this, visit Debug->Exceptions..., then select Add.... Select Common Language Runtime Exception and enter the full typename (including namespace) of the NUnit exception. Finally, in the original exception screen, select your new exception and click Thrown.
Again, you will need to run your tests with the debugger attached in order for it to catch when the exceptions are thrown.
Don't bother with the hassle of attaching to a process. That gets old very quickly. Instead, go to the properties for your unit test project, and and the Debug tab, set "Start external program:" to point to nunit.exe, and add the output dll name in the "Command line arguments" text box (eg UnitTests.dll)