2

I am using OpenCover (and ReportGenerator) to examine my code coverage as part of my CI build process.

Is it somehow possible to have OpenCover fail my build if the coverage doesn't meet a given threshold?

I have looked around but can't find any way to achieve this. Could I peek into the generated report?

EDIT: Sorry, I should have mentioned I am using Nant build scripts.

berko
  • 2,935
  • 4
  • 26
  • 31

1 Answers1

2

As you haven't mentioned what CI server you have or what it uses for scripting I'll respond in a general manner using nant as an example.

If the CI server has the ability to execute XPath queries against an XML document e.g. in nant you can use the xmlpeek task. Then you can use the following query to get the number of sequence points

count(//SequencePoint)

and this query to get the number of visited sequence points

count(//SequencePoint[@vc!='0'])

and from those two numbers you can derive a percentage and then you can then fail the build based on that e.g. in nant you can use the fail task.

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • 1
    Having confused myself slightly, it should possibly be noted that if your filter settings are wrong you can get what appears to be the wrong result for the count of sequence points. I had excluded (or thought I had excluded) a strongly typed DataSet from the coverage metrics by specifying -[\*]{Company Prefix}.{Name of DataSet} in the filters. While this successfully excluded the DataSet from the filtering it _did not_ exclude the nested classes within the DataSet representing the data tables. Adding an additional filter value (-[\*]{Company Prefix}.{Name of DataSet}/\*) fixed things. – Richard J Foster Apr 05 '12 at 20:44