Using variable Code Coverage % with a standardised build script

|
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

<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%

About this Entry

This page contains a single entry by Robert Wray published on January 30, 2009 8:30 AM.

Controls Collection cannot be modified was the previous entry in this blog.

Movable Type annoyance is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.04