Can I get the code coverage percentage from OpenCover

1.1k views Asked by At

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.

1

There are 1 answers

1
Shaun Wilde On BEST ANSWER

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.