Noob help with NCover
Noob help with NCover
Hi all, I've used quite a few code coverage tools with Maven 2 and Java, but this is my first C# coverage tool. I'm having some trouble getting set up initially with a MSBuild process. Once I have that working, I'll get the process up and running on team city. Here is a basic outline of what I want to accomplish.
- Everything is built and executed via an MSBuild file in Teamcity
- Our unit and integration tests are fired off via Nunit and the coverage is recorded
- Our code is deployed to the server, Selenium runs and performs regression testing on our web interface. This coverage is recorded
- The coverage from 2 and 3 are merged into a single report
This is what I've set up for accomplishing number 2. We have a large project with a lot of dependencies, so I'm including only a couple of namespaces that are code we're written for our application. Any guidance would be appreciated, I've looked at the examples but I can't find anything that covers what I want to do. With my current setup, I get an output file of 1kb with no code reports, though all the tests run successfully. Also, for my requirements, which version will I need to purchase?
<!-- Does not require build targets. Assumes the build has taken place elsewhere via another dependency-->
<CreateItem Include="UnitTests\bin\$(Configuration)\UnitTests.dll">
<Output TaskParameter="Include" ItemName="UnitTestAssemblies" />
</CreateItem>
<!-- Create the folder where unit test and coverage logs will go. -->
<MakeDir Directories="$(BuildLogDirectory)"/>
<PropertyGroup>
<CoverageInclusions>
<!-- Exclude view rendering since that's tested with selenium-->
<CoverageInclusion>
<InclusionType>Namespace</InclusionType>
<Pattern>Spidertracks\w*\.(\w*\.)?</Pattern>
<Pattern>true</Pattern>
</CoverageInclusion>
<CoverageInclusion>
<InclusionType>Namespace</InclusionType>
<Pattern>WebModel\.(\w*\.)?</Pattern>
<Pattern>true</Pattern>
</CoverageInclusion>
<CoverageInclusion>
<InclusionType>Namespace</InclusionType>
<Pattern>Common\.(\w*\.)?</Pattern>
<Pattern>true</Pattern>
</CoverageInclusion>
</CoverageInclusions>
</PropertyGroup>
<NCover
ToolPath="$(ExePath)"
TestRunnerExe="$(NUnitPath)"
TestRunnerArgs=""%(UnitTestAssemblies.FullPath)""
CoverageFile="$(BuildLogDirectory)\output.xml"
IncludeAttributes="$(CoverageInclusions)"
/>
<!-- Deploy on IIS and run Selenium or Watin tests-->
<!-- Merge the two results into a single report-->
</Target>
RE: Noob help with NCover
The IncludeAttributes attribute for the MSBuild task specifies that only classes with the given attribute should be included. So, for example, if you have IncludeAttributes="BusinessLogic.MeasureCoverage" then classes that are implemented with that attribute would be included:
[MeasureCoverage] public class SomeBusinessLogic { ... }
I think what you're looking for is the IncludeTypes attribute for the build task, which will let you only include classes in certain namespaces. IncludeTypes does wildcard based matching and separates multiple patterns with a semicolon, so with the inclusions you defined above, your task should look something like:
You can learn more about IncludeTypes at http://docs.ncover.com/ref/3-0/ncover-console/msbuild/profiling-options#it.