Reputation: 40402
When using the NUnit GUI to run unit tests, is there a way to either:
Upvotes: 5
Views: 1282
Reputation: 4805
In addition to attaching to the NUnit process while running tests, you can temporarily add
Debugger.Launch()
either in a SetUpFixture or TestFixtureSetUp or even in a try catch where the anticipated exception is caught.
Upvotes: 0
Reputation: 151
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)
Upvotes: 6
Reputation: 20198
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.
Upvotes: 5
Reputation: 4052
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.
Upvotes: 1
Reputation: 38494
Attach the Visual Studio debugger to the NUnit process, and then run your tests in the NUnit GUI.
Upvotes: 3