Jenkins, OpenCover, NUnit, Code Metrics, Cobertura Oh my!
In this tutorial, we will be talking about how to provide
CI(Continuous Integration) for
.NET projects using
Jenkins. And how to be informed about code and test coverage and code metrics.
• Ensure that Jenkins and Git installed properly with necessary plugins and tools which are defined below.(Info: Extract all tools to
• Jenkins settings should be configured to be able to run C# project and code metrics tool which is needed to prepare report, properly. Meaning by that, MSBuild and Visual Studio Code Metrics Tool should be registered.
• Source code should be pulled to Jenkins from git or any other scm repository.(In this example Github is used.) A Jenkins job is created for this action.
• After pulling the project, another Jenkins job is configured to build solution using MSBuildPlugin which is installed earlier.
• Afterwards, build step should be set to generate OpenCover coverage result using NUnit test runner and another build step should be added to get OpenCover coverage result as an HTML file.
• If you want to convert OpenCover coverage results to Cobertura reports, another build step should be added. There is a nuget package to make this easier which is OpenCoverToCoberturaConverter. (Why Cobertura?)
• After reports, another build step is added to calculate code metrics using VS Code Metrics Power Tool.
• As a post-build action, publishing Cobertura coverage report step should be added using Cobertura for Jenkins.
• And also Jenkins provides publishing reports as HTML files. Again, another post-build step should be added for this using HtmlPublisherPlugin.
• To publish NUnit test results as a post-build action, NUnitPlugin is configured.
• To publish code metrics as a post-build action, Record VS Code Metrics Power Tool Report is configured.
• Metrics Power Tools
Info: Extract all tools(Metrics Power Tools will be installed in Program Files) to
Register Visual Studio Code Metrics Tool
Create Jenkins Build Job
Source Code Management Settings
Jenkins job to get source code from
Jenkins job to build source code using
OpenCover & NUnit
Add build step to generate
OpenCover coverage results using
NUnit test runner.
Add build step to generate html results from
OpenCover coverage results.
Add build step to convert
opencover results to
VS Code Metrics Power Tool
Add build step to calculate
Publish Cobertura Coverage Report
Add post-build step to view code coverage results as
Publish Html Reports
Add post-build step to view code coverage results as html.
Publish NUnit Test Results Report
Add post-build step to view
NUnit test results.
Record VS Code Metrics Power Tool Report
Add post-build step to view
VS Code Metrics Power Tool reports.
Code Coverage - OpenCover
Code Coverage - Cobertura