Skip to content
Derick Bailey edited this page Dec 4, 2010 · 13 revisions

The NCoverReportTask allows you to run verify minimum code coverage and get more detailed reports for your Continuous Integration server, through NCover 3’s NCover Reporting app.

How to use the NCoverReportTask

Here is an example of how to use the NCoverReportTask to run a full coverage report and verify symbol, branch, method, and cyclomatic complexity coverage, using a coverage.xml file that was produced by ncoverconsoletask.

desc "Run a sample NCover Report to check code coverage"
ncoverreport :coveragereport => :ncoverconsole do |ncr|
  ncr.command = "Tools/NCover-v3.3/NCover.Reporting.exe"
  ncr.coverage_files "coverage.xml"
		
  fullcoveragereport = NCover::FullCoverageReport.new
  fullcoveragereport.output_path = "codecoverage/report"
  ncr.reports fullcoveragereport
		
  ncr.required_coverage(
    NCover::SymbolCoverage.new(:minimum => 90),
    NCover::BranchCoverage.new(:minimum => 90, :item_type => :Class),
    NCover::MethodCoverage.new(:minimum => 100)
  )

  ncr.required_coverage NCover::CyclomaticComplexity.new(:maximum => 30, :item_type => :Class)
end

Configuration Options

The following configuration options can be used to change the report that is produced, and the code coverage metrics that are checked.

command (required)

This is the location of the NCover.Reporting.exe file that will be executed. If you don’t provide this, the task will fail with an error message:

NCoverReport.command cannot be nil.

coverage_files (required)

This is an array of .xml coverage files that were produced by running ncoverconsoletask.

YAML configuration

The NCoverReportTask supports configuration via an external YAML file, including auto-configuration with a “ncoverreport.yml” file. For more information, see the yamlconfig page.

reports (required)

This is an array of reports that you want to run against the specified coverage files. You can run multiple reports in a single execution of NCover.Reporting, by appending them to the array or replacing the array entirely.

fullcoveragereport = NCover::FullCoverageReport.new
fullcoveragereport.output_path = "codecoverage/report"
ncr.reports fullcoveragereport

summaryreport = NCover::SummaryReport.new
summaryreport.output_path = "codecoverage/summary/summary-report.html"
ncr.reports summaryreport

The only reports that are supported at the moment are the FullCoverageReport and the SummaryReport. Both of these reports are only available in HTML format.

The output_path is assumed to be a folder that will contain all of the needed files for the report. If you specify a .html file as in the SummarReport example above, this specific .html file will be written as the main report file.

YAML configuration

Both of the reports support configuration via an external YAML file, including auto-configuration with a “fullcoveragereport.yml” or “summaryreport.yml” file. For more information, see the yamlconfig page.

required_coverage (optional)

This setting allows you to specify the required level of code coverage for the various metrics that NCover supports. The example above shows all four of the supported metrics: Symbol, Branch, Method, and CyclomaticComplexity.

Symbol, Branch, Method: minimum (optional)

Each of these three coverage types should have a minimum level of coverage specified. If none is specified, zero (0) is assumed, which will allow any level of coverage to pass. If a minimum level is specified above zero (0), then any failure to reach this minimum requirement will cause the NCoverReportTask to fail the build.

Symbol, Branch, Method, CyclomaticComplexity: item_type (optional)

Each of the coverage types allows you to specify a specific focus of how the coverage is determined. The default, “:View”, aggregates all coverage data into a single value and reports on it directly.

The valid options for item_type are:

  • :View
  • :Namespace
  • :Module
  • :Class

CyclomaticComplexity: maximum (required)

The CyclomaticComplexity coverage lets you specify the maximum complexity allowed in the coverage data (determined by the item_type). If a the actual CyclomaticComplexity of any specified item_type is greater than the maximum specified, the NCoverReportTask will fail.

Example of required_coverage

The following examples illustrate the different ways of setting up a required_coverage option

ncr.required_coverage(
  NCover::BranchCoverage.new(:minimum => 90, :item_type => :Class),
  NCover::SymbolCoverage.new(:minimum => 90)
)
cc = NCover::CyclomaticComplexity.new
cc.maximum = 30
cc.item_type = :Class
ncr.required_coverage cc

YAML configuration

This task supports configuration via an external YAML file. For more information, see the yamlconfig page.

Command Line Options

This task supports additional command line options, including a .parameters collection for passing in options that are not directly supported. For more information, see the commandline task options documentation.