NCover and NUnit Can Play Nicely on x64

Writing

I’m a big fan of NUnit and NCover and I have used them extensively on many projects. One of the recent problems that I have been running into was the inability to run NCover 1.5 (the free version) on an x64 operating system. The error I was getting was either “Profiled process terminated. Profiler connection not established.” or the process would completely lock up after running.

Here is an example build script which has this problem and will run incorrectly on an x64 system:

<?xml version="1.0"?>
<project name="NUnit Integration" default="test">
  <property name="build.dir" value="build\Release" />

  <target name="test" depends="compile,run-tests">    
  </target>
  
  <target name="compile">    
    <msbuild project="src/NUnitNCover.sln">
      <arg value="/property:Configuration=BuildRelease" />                                  
      <arg value="/t:Rebuild" />
    </msbuild>
  </target>

  <target name="run-tests">
    <mkdir dir="test-reports" />    
    <exec program="tools\ncover\NCover.Console.exe"
            workingdir="${build.dir}">
      <arg value="//reg" />
      <arg value="//w &quot;.&quot;" />
      <arg value="//x &quot;..\..\test-reports\Coverage.xml&quot;" />
      <arg value="&quot;..\..\tools\nunit\nunit-console.exe&quot;" />
      <arg value="&quot;NUnitNCover.Tests.dll&quot; &quot;/xml:..\..\test-reports\Tests.xml&quot; &quot;/nologo&quot;" />
    </exec>
  </target>
</project>

So how do we get this working? Well, in the past I had resulted to some CorFlags.exe hackery which was quite suboptimal since you had to do this on each machine outside of the build script. So, it sucked. The fix actually came in a recent version of nunit. They started including a 32-bit build of nunit-console in with the releases. So I know that the fix is going to be a bit anti-climactic, but all you have to do is to start using this 32-bit version of the nunit-console (and make sure you run the console with Admin privileges):

<?xml version="1.0"?>
<project name="NUnit Integration" default="test">
  <property name="build.dir" value="build\Release" />

  <target name="test" depends="compile,run-tests">    
  </target>
  
  <target name="compile">    
    <msbuild project="src/NUnitNCover.sln">
      <arg value="/property:Configuration=BuildRelease" />                                  
      <arg value="/t:Rebuild" />
    </msbuild>
  </target>

  <target name="run-tests">
    <mkdir dir="test-reports" />    
    <exec program="tools\ncover\NCover.Console.exe"
            workingdir="${build.dir}">
      <arg value="//reg" />
      <arg value="//w &quot;.&quot;" />
      <arg value="//x &quot;..\..\test-reports\Coverage.xml&quot;" />
      <arg value="&quot;..\..\tools\nunit\nunit-console-x86.exe&quot;" />
      <arg value="&quot;NUnitNCover.Tests.dll&quot; &quot;/xml:..\..\test-reports\Tests.xml&quot; &quot;/nologo&quot;" />
    </exec>
  </target>
</project>

Yep, if you look real hard you can see it. If you made it this far, then I’ll be nice and let you download a zip so that you can see the entire test project and all the details on how to get this up and running.

Get the sources here!

Once you unzip the sources, just open a console window in the root of the project and type “build”:

build

Then you’ll see the magic happen! If you want to look at the coverage results, just go grab a copy of NCoverExplorer, unzip it, open up NCoverExplorer.exe and browse to the “test-reports” folder. Then just open up coverage.xml. You should then see something like this:

image

Hopefully you found this useful!

Loved the article? Hated it? Didn’t even read it?

We’d love to hear from you.

Reach Out

Leave a comment

Leave a Reply

Your email address will not be published.

More Insights

View All