I have a problem debugging an NUnit test from VisualStudio. I created an empty project (Console Application), then I added references to the NUnit library and wrote a simple tes
Simply configure your test project so that when you hit F5 (Start debugging) or Ctrl-F5 (Start without debugging) it will automatically start NUnit GUI and execute all tests within it. If any breakpoints get hit, you will also be able to simply debug your test code.
A step-by-step guide with images shows you exactly how to do it.
Laziness is the mother of all invention :-)
Assuming you're using a version of Visual Studio other than Express Edition then TestDriven.NET might be of use.
After installing it
Unfortunately you can't use this method with Express editions of visual studio because TestDriven.NET is a plugin for visual studio and the Express editions do not support the use of plugins
You can also run a test in the debugger via a console application:
Inside the Main method of the console application create a new instance of your test fixuture and then call one of the test methods. For example if I have a fixture named MyTests and a test named Test1 I'd write:
var myTests = new MyTests();
myTests.Test1();
Set a breakpoint at the line where you create an instance of the MyTests
class and press F5
If you are using NUnit 2.4 you can put the following code in your SetUpFixture class. (You can do this with older versions but you will need to do whatever equivalent that has to the SetUpFixture
, or copy it in to the test itself.)
[SetUpFixture]
public class SetupFixtureClass
{
[SetUp]
public void StartTesting()
{
System.Diagnostics.Debugger.Launch();
}
}
What Debugger.Launch() does is cause the following dialog to show up when you click Run inside NUnit.
You then choose your running instance of visual studio with your project open (the 2nd one in my screenshot) then the debugger will be attached and any breakpoints or exceptions will show up in Visual Studio.
Had the same problem with NUnit 2.5.3, and eventually found a different solution. See if this works for you:
Open NUnit GUI and go into Tools menu Settings... dialog. Select Assembly Isolation subsection of Test Loader section in Settings tree. Set the Default Process Model to Run tests dierctly in the NUnit process.
I had it set to Run tests in a single seperate process, which is why the debugger could not link my dll under test to the symbols for debugging it. I am still using Use a sperate AppDomain per Assembly for my Default Domain Usage.
Have a look at NHarness on CodePlex.
It's a very simple, reflection based, test runner library, that recognises NUnit attributes, and can be run from a project within Visual Studio Express, allowing debug testing.
It currently has a test class level granularity, but method level calls are, supposedly, going to be added soon.