Building on our previous post, we can take the coverage information generated by OpenCover and generate a report that shows us where our coverage is lacking.
We’ll use the ReportGenerator tool. In an approach that should be familiar by now, we start by adding a NuGet reference to the project and then writing a psake task that finds the report generator tool:
We need an empty folder for the coverage report, so we create one with a configuration task:
It’s worth noting that we try to remove the report target folder if it already exists, creating a new one each time - this is an easy way to try and ensure the file doesn’t contain any debris from the prior coverage report. By using -ErrorAction SilentlyContinue
for both steps, we don’t abort the build if we can’t remove everything - keeping the directory tidy is helpful, but failing to do so shouldn’t be fatal. (I’ve found that sometimes, just sometimes, the script fails to remove one of the HTML files, perhaps because IIS still has the file open.)
Next, we write a Coverage.Report
task that accumulates all the coverage reports generated by OpenCover and generates the report:
We use the wildcard *.opencover.xml
to pick up all the coverage reports and ReportGenerator does the rest. We finish by automatically opening the report in the default browser - you may want to comment out this step if you find it distracting, or if you decide to include the coverage report in your continuous integration build.
The final result is a useful report. The front page summarizes the coverage achieved by our tests:
Even better, you can drill down to see more details of the test coverage, right down to the individual line of code:
Comments
blog comments powered by Disqus