¿Puedo obtener el porcentaje de cobertura del código de OpenCover?

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.

preguntado el 01 de febrero de 12 a las 04:02

1 Respuestas

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 como ejemplo.

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


and this query to get the number of visited sequence points


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 tarea fallida.

Respondido 01 Feb 12, 09:02

You, sir, are a wizard! Thanks heaps. - berko

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

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.