Debug an NUnit test in Visual Studio 2010 with nunit-console-86.exe

This is for my own future reference. I had nunit tests that I was able to debug without any problem in Visual Studio 2008, with a dll that was targeting .Net 2, but I needed a feature in .Net 4 for a POC. I converted the Visual Studio project to VS 2010, and changed the dll  and unit test dll to compile for .Net 4. The tests still ran fine, but I could no longer break in the debugger (from F5). In order to do this, I needed to target .Net 4 framework with the nunit /framework switch (see image), and…

image

to configure nunit-console-x86.exe to run with .Net 4 by commenting out supportedRuntime version=”v2.0.50727” in C:\Program Files (x86)\NUnit 2.6\bin\nunit-console-x86.exe.config, like so:

<?xml version=”1.0″ encoding=”utf-8″?>
<configuration>
  <!–
   The .NET 2.0 build of the console runner only
   runs under .NET 2.0 or higher. The setting
   useLegacyV2RuntimeActivationPolicy only applies
   under .NET 4.0 and permits use of mixed mode
   assemblies, which would otherwise not load
   correctly.
  –>
  <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>

  <runtime>
    <!– Ensure that test exceptions don’t crash NUnit –>
    <legacyUnhandledExceptionPolicy enabled=”1″ />

    <!– Run partial trust V2 assemblies in full trust under .NET 4.0 –>
    <loadFromRemoteSources enabled=”true” />

    <!– Look for addins in the addins directory for now –>
    <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
      <probing privatePath=”lib;addins”/>
   </assemblyBinding>

  </runtime>
 
</configuration>

The top screenshot also shows that I’m redirecting standard output to a file. This is because I’m doing some crude performance analysis in the tests, collecting timing information and then writing it to standard output.  This file (“TestResults.txt”) gets written to the same directory that the dll is in. I’m also targeting a particular test category (“MyCategory”), because the test suite has many more tests, but I only care about one group (aka category).

Advertisements
This entry was posted in ASP.Net, nunit, Web Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s