News

Laurent Kempé MVP

Contact

My status

View Laurent Kempé's profile on LinkedIn
XING


Xbox 360



Map

Locations of visitors to this page

.NET Dudes

Family

French .NET Dudes

Friends

Links

Tech Head Brothers

Run NCover through MSBuild in Team City

After one comment of Chris Walquist on one of my last post about Team City integration of NCover here is the way I run NCover through MSBuild in Team City.

First I need to import the Task of NCover.

<ProjectToolsVersion="3.5"DefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
TaskName="NCoverExplorer.MSBuildTasks.NCover"AssemblyFile="$(NCoverPath)\Build Task Plugins\NCoverExplorer.MSBuildTasks.dll" />
  <UsingTask
TaskName="NCoverExplorer.MSBuildTasks.NCoverExplorer"AssemblyFile="$(NCoverPath)\Build Task Plugins\NCoverExplorer.MSBuildTasks.dll" />

Then I define some properties:

    <!-- NCover -->
    <SolutionFolder>$(MSBuildProjectDirectory)\..\..</SolutionFolder>
    <TestsFolder>$(MSBuildProjectDirectory)\..\..\Tests</TestsFolder>
    <NCoverPath>C:\Program Files\NCover</NCoverPath>
    <NUnitPath>C:\Program Files\NUnit 2.4.6\bin</NUnitPath>
    <TestDll>TechHeadBrothers.Portal.DataAccess.Tests.dll TechHeadBrothers.Portal.DataAccess.dll</TestDll>
    <CoverageFile>..\..\Tests\Output\Coverage.xml</CoverageFile>
    <CoverageExclusions>Assembly=*.Tests</CoverageExclusions>
    <CoverageAssemblies>TechHeadBrothers.Portal.DataAccess;TechHeadBrothers.Portal.Domain;</CoverageAssemblies>

Then I have two targets:

  <Target Name="FullCoverage">
    <Message Text="#--------- Executing NCover ---------#" />
    <NCover ToolPath="$(NCoverPath)" 
            CommandLineExe="$(NUnitPath)\nunit-console.exe" 
            CommandLineArgs="$(TestDll)" 
            WorkingDirectory="$(TestsFolder)\Output\bin\Debug" 
            ProjectName="$(ProjectName)" 
            CoverageFile="$(CoverageFile)" 
            FileExclusionPatterns="$(CoverageExclusions)" 
            LogFile="Coverage.log" 
            AssemblyList="$(CoverageAssemblies)" />
    <!-- Summary Page -->
    <NCoverExplorer ToolPath="$(NCoverPath)" 
                    ProjectName="$(ProjectName)" 
                    OutputDir="$(TestsFolder)\Output" 
                    CoverageFiles="$(CoverageFile)" 
                    SatisfactoryCoverage="80" 
                    ReportType="ModuleClassSummary" 
                    HtmlReportName="CoverageSummary.html" />
    <!-- Full HTML Report -->
    <NCoverExplorer ToolPath="$(NCoverPath)" 
                    ProjectName="$(ProjectName)" 
                    OutputDir="$(TestsFolder)\Output\Coverage" 
                    CoverageFiles="$(CoverageFile)" 
                    SatisfactoryCoverage="80" 
                    ReportType="FullCoverageReport" 
                    HtmlReportName="Coverage.html" />
  </Target>

And finally in the target AfterBuild (more on that in this post) I call target SummaryCoverage or FullCoverage according to the configuration:

  <Target Name="AfterBuild">
    <CallTarget Condition=" '$(Configuration)' == 'Staging' " Targets="SummaryCoverage" ContinueOnError="false" />
    <CallTarget Condition=" '$(Configuration)' == 'Nightly' " Targets="FullCoverage" ContinueOnError="false" />

That's it!

Then Chris asked the following:

1) How did you get your "tests" tab to show up as well?  Did you have to run the tests with NUnitLauncher, and then run again for coverage?  I read that NUnitLauncher can't be used to profile, since it kicks off a separate process.

2) How did you get the "classes", "header", "index", etc. files?  I just get the summary.html.  I see options for this in ncover.console.exe but not in the <NCoverExplorer> target.

3) Did you use wildcard expressions to pass a list of test assemblies to NCover?  If so, would like to see how you did that, too.

1) I get the test tab configuring Team City to run my unit tests. That has nothing to do with NCover. And yes doing it so seems to run two time all unit tests. Here is a screen shot of my team city runner configuration:

2) Read this post "Using NDepend in Team City build management tool" that talks about for NDepend but shows configuration for NCover too.

3) The answer is on top of this post!

Hope it helps!

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# April 30, 2008 8:49 AM

Jeroen Bok said:

Thnx for the great info. I've used your article to get my ncover output in the teamcity dashboard.

TeamCity provides it's own nunit (and vsts) test launcher that you can use in your build script.

This automatically shows your test results in your dashbard, without running the tests twice.

www.jetbrains.net/.../.Net+Testing+Frameworks+Support

So in your build script (i use NAnt myself) you can let NCover use the TeamCity test launcher in stead of the normal nunit.console.exe.

# May 6, 2008 4:44 AM

simone_b said:

Thanks for the post Laurent, it really helped me start integrating NCover in my build process.

Some points to watch out for:

- NCover is no longer free, the latest free version (1.5.8) can't profile assemblies on 64 bit machines.

- NCoverExplorer is no longer free, the latest free version (1.4.0.7) doesn't have the FullCoverageReport report type.

# May 29, 2008 7:06 AM

ronnie v said:

Awsome post!  I stuggled pretty badly on getting ncover working with ccnet and your post did it for me.

Thanks

# July 11, 2008 7:51 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)