Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I cause the NUnit GUI to break into the Visual Studio debugger on a breakpoint/failed test?

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?
like image 266
Nick Meyer Avatar asked Jul 23 '10 16:07

Nick Meyer


People also ask

How do I debug NUnit tests in Visual Studio?

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.

How do I debug in NUnit?

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.

How do I fix breakpoint in Visual Studio?

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.


3 Answers

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)

like image 119
Jim Cooper Avatar answered Nov 03 '22 01:11

Jim Cooper


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.

like image 26
Steve Guidi Avatar answered Nov 02 '22 23:11

Steve Guidi


Attach the Visual Studio debugger to the NUnit process, and then run your tests in the NUnit GUI.

like image 44
Tim Lloyd Avatar answered Nov 03 '22 01:11

Tim Lloyd