Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run NUnit in debug mode from Visual Studio?

When I need to debug my NUnit tests, I simply attach to the NUnit GUI application nunit-agent.exe using "Debug|Attach to Process" and run the tests from the GUI. Any breakpoints in my tests (or the code they're testing) are hit. Am I misunderstanding your question, or will that work for you?


I use the same technique as you are trying Jon, without the /assembly flag, i.e.

Start External Program: C:\Program Files\NUnit 2.4.8\bin\nunit.exe

Command line arguments: "<path>\bin\Debug\Quotes.Domain.Tests.dll"

Does TestDSP.dll contain all your TestFixtures?

As my test project is not the startup project in the solution, I run my tests by right-clicking on the test project and choosing Debug --> Start New Instance


Simply remove the line that looks like

<ProjectTypeGuids>
    {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>

from your project file. This line basically tells VS.Net that it's a Test project, thus the "Cannot start test project". FYI here the 1st Guid says "it's a test", the 2nd says "it's C#". For information on those Guids: http://www.mztools.com/Articles/2008/MZ2008017.aspx


In addition to the answer provided by @Justin here are some more details for NUnit 2.6.

Using NUnit 2.6 attach to nunit.exe or nunit-console.exe and NOT the agent. The configuration noted by @Justin is slightly different. Below is an example from nunit.exe.config (same for nunit-console.exe.config).

<startup useLegacyV2RuntimeActivationPolicy="true">
  <!-- Comment out the next line to force use of .NET 4.0 -->
  <supportedRuntime version="v2.0.50727" />  
  <supportedRuntime version="v4.0.30319" />
</startup>

For .NET 4 test project, to get break points to hit, you will have to comment out or remove the v2.0 line as the comment suggests. Once I did that I was able to debug the .NET 4.0 test project.