NCover Documentation

Please visit NCover and Cruise Control Integration for updated information.

Note: Starting with version 1.5, CC.NET offers native NCover tasks.

The NCover Profiler and NCover Reporting tasks are well-documented, and should be simpler to configure and maintain implementing NCover from MSBuild or NAnt scripts.

However, if you can't or don't want to upgrade to CC.NET 1.5, or simply want to preserve your existing build scripts, then the build target directions below will still work.

What is CruiseControl.NET?

CruiseControl.NET is a free, open-source, Java-based Continuous Integration (CI) server that monitors a source code repository for changes and executes a build script when updates occur. Since the code integration is controlled by the ccnet.config script, CC.NET can also be configured to run NCover on your tests and create code coverage reports from the results. More information about CC.NET can be found on its homepage. The rest of this article describes how to set up a CC.NET project that runs NCover and then creates a report from the gathered coverage information.

Creating build targets for CC.NET to use

Before you can even set CC.NET up, your build script must have a task that uses NCover to measure your unit test coverage. The simplest way to create a build target to do that is to get NCover working in NCover Explorer (perhaps with the help of the articles here and then use the "Script Helper" tool to generate a custom NAnt or MSBuild target. In the example below we're using NUnit as our unit testing framework.

First, the MSBuild target:

<Target Name="CoverMyCode">
    <NCover ToolPath="C:\Program Files\NCover\"
        TestRunnerExe=".\external\nunit\v2.0\nunit-console.exe"
        TestRunnerArgs=".\release\ncover.test.unit.dll /xml NCover-NUnit-Results.xml"
        CoverageFile="unittest_coverage.xml"
        ExcludeAssemblies="NCover.Test.*;NCover.Framework.XmlSerializers"
    />
</Target>

And then the equivalent NAnt target:

<target name="CoverMyCode">
    <ncover program="C:\Program Files\NCover\NCover.Console.exe"
        testRunnerExe=".\external\nunit\v2.0\nunit-console.exe"
        testRunnerArgs=".\release\ncover.test.unit.dll /xml NCover-NUnit-Results.xml"
        coverageFile="unittest_coverage.xml"
        excludeAssemblies="NCover.Test.*;NCover.Framework.XmlSerializers"
    />
</target>

Great! Add the target to your build script and make sure it executes without errors from the command line. Once it does, you need to create another target in your build script, this one to create a coverage report from the coverage information that is gathered in the task you just wrote. Unfortunately, this task isn't automated in NCover Explorer for you, but the documentation is extensive and should help you finish in no time at all.

First, the MSBuild target:

<PropertyGroup>
    <Reports>
        <Report>
            <ReportType>SymbolModule</ReportType>
            <Format>Xml</Format>
            <OutputPath>.\coverage\symbolmodule.xml</OutputPath>
        </Report>
    </Reports>
</PropertyGroup>
<Target Name="CreateCoverageReports">
    <NCoverReporting ToolPath="C:\Program Files\NCover\"
        CoverageDataPaths="unittest_coverage.xml"
        OutputReport="$(Reports)"
    />
</Target>

And then the equivalent NAnt target:


<target name="CreateCoverageReports">
    <ncoverreporting program="C:\Program Files\NCover\NCover.Reporting.exe">
      <coverageDataPaths>
        <include name="unittest_coverage.xml" />
      </coverageDataPaths>
      <reports>
        <report format="Xml"
                outputPath=".\coverage\symbolmodule.xml"
                reportType="SymbolModule" />
      </reports>
    </ncoverreporting>
</target>

Before you continue, add the target to your build script and make sure everything works from the command line. CC.NET doesn't exactly make build script errors easy to see and figure out, so make sure that everything works before you add the additional complexity of CC.NET on top. Once everything is working, it's time to start configuring CC.NET.

Configuring the CC.NET Server to create coverage reports

First, you need to locate the server config file, which is typically located in "[cc.net installation directory]\server\ccnet.config". Open the file in a plain text editor, and add a new node, or use an existing one. The CC.NET website has excellent instructions on how to set up a new CC.NET project and configure tasks here.

Once you have a working CC.NET install and project that triggers a build when a new checkin is made, your project should look something like this:

<project name="MyProject"> <webURL>http://mybuildserver/ccnet/</webURL> <workingDirectory>C:\Integration\MyProject\WorkingDirectory</workingDirectory> <artifactDirectory>C:\Integration\MyProject\Artifacts</artifactDirectory> <modificationDelaySeconds>10</modificationDelaySeconds> <!-- <triggers /> control when the project builds --> <!-- <sourcecontrol /> tells CC.NET what source repository you're using (CVS, SVN, etc) and how to get data from it --> <tasks> <msbuild> <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable> <workingDirectory>C:\dev\ccnet</workingDirectory> <projectFile>mybuildscript.proj</projectFile> <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs> <targets>BuildMyProject</targets> <timeout>900</timeout> <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger> </msbuild> <!-- other tasks here ... --> </tasks> <publishers> <xmllogger /> </publishers> </project>

Next, you need to add two tasks to the section of the that call the two build targets in your build script that run NCover and create coverage reports. The example below uses the () CC.NET task, but CC.NET also supports a task and an task. The should look something like this once you're done.


<project name="MyProject">
    <webURL>http://mybuildserver/ccnet/</webURL>
    <workingDirectory>C:\Integration\MyProject\WorkingDirectory</workingDirectory>
    <artifactDirectory>C:\Integration\MyProject\Artifacts</artifactDirectory>
    <modificationDelaySeconds>10</modificationDelaySeconds>
    <!-- <triggers /> control when the project builds -->
    <!-- <sourcecontrol /> tells CC.NET what source repository you're using (CVS, SVN, etc) and how to get data from it -->
    <tasks>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
            <workingDirectory>C:\dev\ccnet</workingDirectory>
            <projectFile>my_build_script.proj</projectFile>
            <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs>
            <targets>BuildMyProject<span style="font-weight:bold;">;CoverMyCode;CreateCoverageReports</span></targets>
            <timeout>900</timeout>
            <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
        </msbuild>
        <!-- other tasks here ... -->
    </tasks>
    <publishers>
        <xmllogger />
    </publishers>
</project>

Finally, you need to add the xml reports that NCover.Reporting creates to the section, like so:

<project name="MyProject"> <webURL>http://mybuildserver/ccnet/</webURL> <workingDirectory>C:\Integration\MyProject\WorkingDirectory</workingDirectory> <artifactDirectory>C:\Integration\MyProject\Artifacts</artifactDirectory> <modificationDelaySeconds>10</modificationDelaySeconds> <!-- <triggers /> control when the project builds --> <!-- <sourcecontrol /> tells CC.NET what source repository you're using (CVS, SVN, etc) and how to get data from it --> <tasks> <msbuild> <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable> <workingDirectory>C:\dev\ccnet</workingDirectory> <projectFile>mybuildscript.proj</projectFile> <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs> <targets>BuildMyProject;CoverMyCode;CreateCoverageReports</targets> <timeout>900</timeout> <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger> </msbuild> <!-- other tasks here ... --> </tasks> <publishers><span style="font-weight:bold;"> <merge> <files> <file>C:\dev\ccnet\coverage\symbolmodule.xml</file> </files> </merge></span> <xmllogger /> </publishers> </project>

Configuring the Webdashboard to display coverage reports

Before CC.NET can display the code coverage reports on the project home page, you'll need to copy several files from the NCover installation directory to the CC.NET installation directory.

  • Copy "[ncover installation directory]\CC.Net\NCoverReporting30.xsl" to the "[cc.net installation directory]\webdashboard\xsl\" folder.
  • Copy "[ncover installation directory]\CC.Net\g.png" to the "[cc.net installation directory]\webdashboard\images\" folder.
  • Copy "[ncover installation directory]\CC.Net\r.png" to the "[cc.net installation directory]\webdashboard\images\" folder.
  • Copy "[ncover installation directory]\CC.Net\y.png" to the "[cc.net installation directory]\webdashboard\images\" folder.

Once the files have been copied, you need to open the CC.NET webdashboard configuration file, which is usually located at "\webDashboard\dashboard.config", and update the section as illustrated below.

<buildPlugins> <buildReportBuildPlugin> <xslFileNames> <xslFile>xsl\header.xsl</xslFile> <xslFile>xsl\modifications.xsl</xslFile> <xslFile>xsl\compile.xsl</xslFile> <xslFile>xsl\unittests.xsl</xslFile> <xslFile>xsl\MsTestSummary.xsl</xslFile> <xslFile>xsl\fxcop-summary.xsl</xslFile>
<!-- Add the following element --><span style="font-weight:bold;"> <xslFile>xsl\NCoverReporting30.xsl</xslFile></span> <xslFile>xsl\SimianSummary.xsl</xslFile> <xslFile>xsl\fitnesse.xsl</xslFile> </xslFileNames> </buildReportBuildPlugin> <buildLogBuildPlugin /> <xslReportBuildPlugin description="NUnit Details" actionName="NUnitDetailsBuildReport" xslFileName="xsl\tests.xsl" /> <xslReportBuildPlugin description="NUnit Timings" actionName="NUnitTimingsBuildReport" xslFileName="xsl\timing.xsl" /> <xslReportBuildPlugin description="NAnt Output" actionName="NAntOutputBuildReport" xslFileName="xsl\Nant.xsl" /> <xslReportBuildPlugin description="NAnt Timings" actionName="NAntTimingsBuildReport" xslFileName="xsl\NantTiming.xsl" /> <xslReportBuildPlugin description="FxCop Report" actionName="FxCopBuildReport" xslFileName="xsl\FxCopReport.xsl" /> <!-- Add the following element --> <span style="font-weight:bold;"><xslReportBuildPlugin description="NCover Report" actionName="NCoverBuildReport" xslFileName="xsl\NCoverReporting30.xsl" /></span> <xslReportBuildPlugin description="Simian Report" actionName="SimianBuildReport" xslFileName="xsl\SimianReport.xsl"/> <xslReportBuildPlugin description="Fitnesse Report" actionName="FitnesseBuildReport" xslFileName="xsl\FitnesseReport.xsl"/> </buildPlugins>

That's it! If you have CC.NET running as a windows service, you'll need to restart the CC.NET service to force it to pick up the changes in the "webdashboard.config" and "server.config" files. Once the service has restarted, you should be able to see your NCover code coverage report after the next checkin!

If you don't see the report, please don't hesistate to send us a support request.

If you still need technical assistance, we can help:

Submit A Support Ticket