3
votes

Trying to debug an NUnit test in VS2010 and is not stopping on the breakpoint. It was working the last time I tried need to debug the test (maybe 1 yr ago) but now it doesn't work.

I've tried the following:

I've tried attaching, rechecking my installation, updated the config file so it's using the 4.0 runtime, still doesn't hit the breakpoint.

What am I missing?

10
Have You Tried Turning It Off And On Again?Juan Carlos
Which config file did you check? You must put <supportedRuntime version="v4.0.30319" /> in nunit.exe.configAmy B
Yes. I've toggled the breakpoint, restarted the dev machine, I even upgraded Nunit.Bill Martin
Added it to the nunit.exe.config. Just for grins, I added it to the other nunit configs (nunit-agent, nunit-agent-x86, nunit-console-x86)Bill Martin
Have you tried attaching the debugger to the nunit-agent process instead of the nunit process?Matthew Strawbridge

10 Answers

2
votes

This is a long overdue question but I haven't seen the solution to debug NUnit tests directly within Visual Studio. This is quite easily possible and without any third party tools. All you have to do is configure your test project (which is just a plain old Class library project) so it will start NUnit test runner whenever you hit F5 or Ctrl-F5 (just run, no debugging).

Particularly you will have to configure your project properties to start an external program:

Project configuration

Step by step configuration is very well described in this blog post. It advises you to use NuGet to obtain NUnit test runner and configure project to execute the runner when you try running your library project. As simple as that. Using no specific tools which are usually not free.

2
votes

You can debug nunit tests in VS studio community version only. For this you need to install Nunit3testAdpter. You can add this in Tools -> Extension and updates. or from Nuget packages.

1
votes

There are multiple reasons why this may happen. If your application's target framework is different from NUnit's, then you won't be able to debug, because the tests are actually being run by nunit-agent.exe.

For me, my application was using 4.5, but NUnit's was using 3.5. (You can find this from one of the NUnit GUI applications -> Help -> About)

To fix this, change the nunit.exe.config file to include the following, inside the configuration section:

<startup>
  <requiredRuntime version="4.0.30319" />
</startup>
1
votes

This can also happen when your PDB generation is set to embedded. Switching it to full will allow the nunit test adapter to start with the debugger attached. At that point it can be switched back to embedded and it will debug again.

The setting is on the project properties pages, in the Build tab, then click the Advanced button. I always choose "All Configurations" at the top, so I make sure I'm emitting a useful PDB (or embedding the info) when building Release configuration assemblies too. enter image description here

0
votes

The other day I failed to hit a breakpoint in my NUnit debugging. It took me a while to realize that someone had copy/pasted the test into a different file and I was running a different test than the one that the breakpoint was in.

0
votes

I recently had a similar problem. Changing the project's platform to AnyCPU solved it for me. Also worth checking:

1) Check NUnit's latest version (I was using 2.5.7, updated to 2.6.2) 2) The Target Framework for your test project. I was using .NET 4.0 (you can find it under Properties -> Application, on VS2010)

0
votes

At least up to vs2010 the debugger can only debug 32 bit apps but not 64 bit apps.

With vs2010 I am using a 32bit nunit.exe version and use "attach to debugger". This workes well for me.

0
votes

Please upgrade NUnit Test Extension and close the Visual studio so Visx (probably spell) will run and update NUnit tool. After this you can open your project and run NUnit test project. It will run. I tested accurately.

-1
votes

Try changing the test to x64. From the menu do

Test -> Test Settings -> Default Processor Architecture -> x64.

-3
votes

i think u cant debug with Visual studio. better u install TestDriven.NET.

then

  1. Put the BreakPoint on the test method
  2. Right click on the test method.
  3. select TestWith->Debugger