Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top