Publish .Net Core Code Coverage Results with ReportGenerator in Jenkins

Georg Dangl by Georg Dangl in Continuous Integration Wednesday, October 11, 2017

Wednesday, October 11, 2017

Publish .Net Core Code Coverage Results with ReportGenerator in Jenkins
Posted in DotNet Jenkins xUnit

I've blogged before about automating your .Net Core test, deploy and coverage work flow with Jenkins. When visualizing coverage reports, I'm usually sticking to what's built into Jenkins. I've dabbled with the ReportGenerator before, but was content with the well-known Cobertura Plugin.

The only working solution currently that supports both .Net and .Net Core for capturing code coverage, OpenCover, doesn't output the Cobertura format by default and thus needs the OpenCoverToCoberturaConverter. Recently, it's author, Daniel Palme, suggested I could try out the ReportGenerators new version. Since he's the author of a library I use in literally every single project, both private and at work, I was excited to check the ReportGenerator out again. In short: It's great! The visualization looks modern, chic and it's enriched with additional metadata such as cyclomatic complexity and the famous CRAP score.

It's also really simple to set up. Please check out this sample project, which you can either clone or download directly, to have a basic starter for a .Net Standard library with .Net Core unit tests, including code coverage. It's fairly simple to get started and have a great foundation for expaning your code base. You only need to know these steps to get more confidence in your code evolution:

A PowerShell script, TestsAndCoverage.ps1, which runs the tests, gathers coverage data and builds the Html report:

A Jenkins instance configured to check out your code, run the script and publish both your test results and the generated report:

Report Generator Configuration in Jenkins

After your first run, there'll be a Code Coverage Report entry in your Jenkins job that gives you a detailed breakdown of your coverage. You can even easily configure additional features such as keeping a history with ReportGenerator.

As always, spend some minutes at the beginning of your project to configure automatic testing, coverage and reporting on every code push and you'll save future-you a ton of trouble later when you've already acquired a lot of technical debt.

Happy Analyzing!



Share this post

comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.


Need a consultant for BIM, GAEB or Software Development?

Contact me at [email protected], +49 (173) 56 45 689 or visit my professional page!

// Just 💗 Coding

Social Links