3

I've just "upgraded" from NUnit 2.5.2 to NUnit 2.5.7 so that I can run unit tests against an DLL's built with .Net Framework 4. I've been using 2.5.2 for a long time via the "StartExternalProgram" property under project properties. I've never had to explicitly debug attach to the NUnit process in that scenario.

Now under 2.5.7 it appears that one must explicitly attach to the NUnit_Agent process in order to debug the code under test.

Of course this means that instead of requiring two clicks to run my unit tests I now have to click Debug.Run icon in VS2010, wait for NUnit GUI to appear, alt-Tab back to VS2010, click Debug.Attach.., scroll down the list to find NUnit Agent, double click to select it, alt-Tab back to NUnit GUI, click Run to run the test(s).

So, is there a reason that using NUnit has become that much more difficult under 2.5.7 or did a ball get dropped?

Thanks in advance for any advice on restoring the "automagic attach" from earlier versions.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Bill Cohagan
  • 379
  • 3
  • 9

2 Answers2

6

The problem is that NUnit is kicking off a child process (nunit-agent.exe.) I was able to fix this by opening up nunit.exe.config and adding the following section:

<startup>
    <supportedRuntime version="v4.0.30319" />
</startup>

Edit: If you still want to use nunit with .Net 2.0, make sure to add that version as well. My config ended up looking like this:

<startup>
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0.30319" />
</startup>

Edit 2: I also recently found that the order of the entries also makes a difference.

Pedro
  • 12,032
  • 4
  • 32
  • 45
  • Tried this and no joy; i.e., breakpoint not hit. I'm using the x86 variant, but can't see how that'd make a difference. I added the element as the first subelement of the element in the file, nunint-x86.exe.config. I'm curious as to why adding this element would avoid the launching of the agent process? – Bill Cohagan Aug 25 '10 at 14:43
  • As far as I can tell, the agent process is kicked off if you are using a different runtime than the supported one(s). – Pedro Aug 25 '10 at 17:53
  • Any idea why this isn't working for me? I notice that the agent process is *not* spun up -- so that aspect of the fix seems to work; however when I run the app and NUnit starts up, running the tests ignores any breakpoints I have set. How about settings within NUnit itself (under Tools.Settings?) I tried "Run tests directly in the NUnit process" as it seemed the obvious choice, but that didn't help. Any other ideas? – Bill Cohagan Aug 26 '10 at 17:14
  • Turning Shadow Copy on or off might change the behavior, but I'm not sure if that is causing the problem... – Pedro Aug 30 '10 at 13:28
  • +1 ah, this did the trick for me! thanks very much. I had instead of . I will read up on the differences, but for now, that did the trick. Thanks! – Dave Dec 14 '10 at 18:00
  • 1
    @Pedro: The complete solution is in this [link][http://stackoverflow.com/questions/930438/nunit-isnt-running-visual-studio-2010-code] – mas_oz2k1 Mar 11 '11 at 04:23
0

Perhaps not quite an answer to your problem, but a different way of looking at it: Resharper includes a component that runs nunit tests within the VS2010 gui without needing any separately configured external programs. This might simplify things for you?

user264636
  • 155
  • 1
  • 2
  • 5
  • Might give it a try if can't find another solution; however another option is to use VS2010's built in Test support. I prefer NUnit, but not with all the extra hoo-hah. – Bill Cohagan Aug 25 '10 at 14:41