Recently in NCover Category
A couple of things to remember:
- Most, if not all, of your installed tools that the build scripts use will need any references to C:\Program Files\ changed to C:\Program Files (x86)
- Force ncover and nunit-console to 32-bit. Seriously, if you get the message "Profiled process terminated. Profiler connection not established" when chaining nunit-console through ncover, follow those instructions.
At the moment one of my projects is to harmonise all our build scripts so instead of having one per project (DLL's, Websites, WebServices, WinServices, EXE's) we have a StandardDLL, StandardWebsite, StandardWebService,.... This will take us down from over 50 build scripts to approximately 10-15 once "system" ones are included.
One thing that caused me a small problem was the fact that, within our DLL's, we have different levels of coverage attained and there is no realistic likelihood of the level of coverage being harmonised anytime soon (Yes, yes, ideal world = 100% coverage, etc). So, how to achieve this when using a standardised build script called StandardDLL.build?
The Build Script
The key bit is marked in bold, the "satisfactoryCoverage" node. I needed a way to have this configurable on a per-project basis, but without having to specify it for all projects (Just to be awkward!).
The Solution
It turned out the solution was quite simple; firstly replace the hard-coded "90" with "${satisfactoryCoverage}", i.e. a nant property. Secondly, add a new action just above the ncover node, i.e. between it and the <target> parent node that is as follows:
One thing that caused me a small problem was the fact that, within our DLL's, we have different levels of coverage attained and there is no realistic likelihood of the level of coverage being harmonised anytime soon (Yes, yes, ideal world = 100% coverage, etc). So, how to achieve this when using a standardised build script called StandardDLL.build?
The Build Script
<target name="ncoverage">
<ncover program="${ToolsPath}\ncover\1.5.6\NCover.Console.exe"
commandLineExe="${ToolsPath}\nunit\bin\nunit-console.exe"
commandLineArgs="${ProjectName}.Test.dll /xml=${NCoverOutput}\${ProjectName}_Coverage.xml /labels /nologo"
workingDirectory="${ProjectBasePath}\src\test\bin\${configuration}\"
coverageFile="${NCoverOutput}\${ProjectName}_Coverage.xml"
logLevel="Verbose"
logFile="${ProjectBasePath}\src\test\bin\${configuration}\ncover.log"
excludeAttributes="CoverageExcludeAttribute;System.CodeDom.Compiler.GeneratedCodeAttribute">
<assemblies basedir="${ProjectBasePath}\src\test\bin\${configuration}\">
<include name="${ProjectName}.dll" />
<exclude name="*.Test.dll" />
</assemblies>
</ncover>
<ncoverexplorer
program="${ToolsPath}\NCoverExplorer\ncoverexplorer.console.exe"
outputDir="${NCoverOutput}\"
satisfactoryCoverage="90"
reportType="4"
failMinimum="true"
projectName="${ProjectName}"
xmlReportName="${ProjectName}_Coverage_Report.xml">
<fileset>
<include name="${NCoverOutput}\${ProjectName}_Coverage.xml" />
</fileset>
</ncoverexplorer>
</target>
The key bit is marked in bold, the "satisfactoryCoverage" node. I needed a way to have this configurable on a per-project basis, but without having to specify it for all projects (Just to be awkward!).
The Solution
It turned out the solution was quite simple; firstly replace the hard-coded "90" with "${satisfactoryCoverage}", i.e. a nant property. Secondly, add a new action just above the ncover node, i.e. between it and the <target> parent node that is as follows:
<if test="${not property::exists('satisfactoryCoverage')}">
<property name="satisfactoryCoverage" value="90" />
</if>
This node makes sure that the satisfactoyCoverage property exists and is set to a default value of 90. Now, onto specifying it as a custom value when required:
<tasks>
<nant>
<buildFile>C:\BuildServer\BuildScripts\StandardDLL.build</buildFile>
<buildArgs>-D:satisfactoryCoverage=85</buildArgs>
That's a snippet from the <project> node for a given project in the ccnet.config file. By specifying that build argument, the satisfactoryCoverage for that project will be 85%, rather than the standard 90%
A couple of articvles that are worth reading that have been sat in open tabs since my recent bout of NCover based learning:
Reporting on NCover Exclusions (Basildon Coder)
Advocating the use of code coverage
Reporting on NCover Exclusions (Basildon Coder)
Advocating the use of code coverage
