When using the NUnit GUI to run unit tests, is there a way to either:
If you would like to debug your tests, use the Visual Studio Debug | Processes... menu item to attach to NUnit after starting it and set breakpoints in your test code as desired before running the tests.
Debugging the adapter is done by first creating a debug version of the adapter. You can then enable a debug run by passing one of the NUnit debug settings using runsettings. The last setting is equal to setting both of the two above.
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
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)
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.
Attach the Visual Studio debugger to the NUnit process, and then run your tests in the NUnit GUI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With