Gallio: Measuring Test Quality With NCover

The Gallio Project is an effort to provide a common, consistent interface for the numerous .NET testing frameworks available. Although the Gallio tools are easy to use, how to get them to work with NCover is not obvious. This article explains how to get NCover working with the Gallio framework.

Covering Tests From The Command Line

Covering tests run with Gallio ends up being quite simple. Just take whatever working Gallio command line you have, stick a call to ncover.console.exe in front of it, and add the “//pm gallio.host.exe” argument. For example, if your working Gallio command line looks like this:

gallio.echo.exe .\release\ncover.test.unit.dll

Then gathering coverage on your tests will look like this:

ncover.console.exe //pm gallio.host.exe "C:\program files\gallio\bin\gallio.echo.exe" .\release\ncover.test.unit.dll

Covering Tests From NCover Explorer

Now that you have a working command line that gathers coverage with NCover and Gallio, setting up an NCover Explorer project just means transfering that data to the right fields in NCover Explorer’s Project Configuration window, as was done in the screenshot below. The Working Folder field should be the directory your test assemblies are in.

coverage_gallio_ncover_1.png

Once the fields on the Application to Profile page have been populated, you need to visit the Advanced Options page and enter “gallio.host.exe” into the Profiled Process Name field.

coverage_gallio_ncover_2.png

A curiousity of the Gallio framework is that even though it installs in the x86 version of Program Files on x64 machines, the x64 version of NCover.Console must be used to gather coverage data from tests run with Gallio, so that even on x64 machines, there is no need to visit the NCover Path page. Once you've finished with the Advanced Options page, the NCover Explorer project is ready to run. Close the Project Configuration window and click the green Run Coverage button to run NCover and start looking at coverage data!

Covering Tests From A Build Script

Well, now that you’ve set up a project in NCover Explorer, getting coverage from an automated build script is just a click away. Press the Script Helper button and select any of the tasks to have NCover Explorer generate the build script for you. The NAnt NCover task is shown below.

<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by NCover Explorer at http://www.ncover.com/ -->
<project name="NCoverCoverage" default="coverage" xmlns="http://nant.sf.net/schemas/nant.xsd" >

  <!-- TODO: Uncomment and add the full path to NCover.NAntTasks.dll if not in your path -->
  <!-- TODO: Alternatively, remove this line if you have copied the .dll to your NAnt bin folder -->
  <!-- <loadtasks assembly="NCover.NAntTasks.dll"/> -->
  <target name="coverage" description="Generate code coverage using NCover">
    <ncover program="C:\Dev\NCover\Main\Release\ncover.console.exe"
            testRunnerExe="C:\Program Files (x86)\Gallio\bin\Gallio.Echo.exe"
            testRunnerArgs="ncover.test.unit.dll"
            workingDirectory="C:\dev\ncover\main\release\"
            coverageFile="C:\Dev\NCover\Main\coverage.xml"
            symbolSearchLocations="Registry, SymbolServer, BuildPath, ExecutingDir"
            coverChildProcess="gallio.host.exe"
            projectName="Basic"    />
  </target>
</project>

Plug the coverage target or the NCover task into your build script wherever makes the most sense. If you would like to integrate your build script's results into your build server's interface, read one our articles describing how to integrate NCover into your [build server](/how-to/using-ncover-with-your-build-server/).

Questions? Comments?

Contact us.