DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. ASP.NET Core Code Coverage Reports On Azure DevOps

ASP.NET Core Code Coverage Reports On Azure DevOps

We take things a step further by demonstrating how to generate ASP.NET coverage reports on Azure DevOps.

Gunnar Peipman user avatar by
Gunnar Peipman
·
Mar. 22, 19 · Tutorial
Like (3)
Save
Tweet
Share
16.31K Views

Join the DZone community and get the full member experience.

Join For Free

After making ASP.NET Core code coverage reports work on a local box, I took it a step further and made code coverage reports available also on Azure DevOps. This blog post shows how to generate code coverage reports for .NET and ASP.NET Core applications on Azure DevOps.

Getting Started

This blog post expects that there is .NET or ASP.NET Core project with unit tests and code coverage reports. It also assumes the existence of an Azure DevOps build pipeline that is connected to a source code repository. It's covered well on a previous blog post about automated testing, "Code coverage reports for ASP.NET Core."

Here is the build pipeline of one of my sample applications. I highlighted the report generator task on the screenshot. Notice also date based versioning task in the pipeline.Image title

The report generator is run after tests because before the tests we didn't have test results or code coverage data.

Configuring Unit Tests

Most of the important work is done when unit tests are run. This is why we need to configure the test task first. Here is an example. We configure a unit test task that runs unit tests, gathers code coverage information, and saves the results to a build server disk. The results are XML files we need as an input for code coverage reports.Image title

Here is the arguments block as text for copy and paste. It must be all one line with no line breaks in Arguments field of test task.

--configuration $(BuildConfiguration)
 /p:CollectCoverage=true
 /p:CoverletOutputFormat=cobertura 
 /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\

Run build to see if the test task succeeds and there are no errors and warnings.

Adding Code Coverage Reports

For code coverage reports we take the free ReportGenerator task by Daniel Palme from Visual Studio Marketplace. If you also need local code coverage reports then check out the ReportGenerator project from GitHub.

If an organization under a build pipeline that belongs doesn't have this task yet, then the task is first added to the organization and then it can be added to the build pipeline. Here is how to configure the ReportGenerator task.Image title

The report types field specifies what type of reports we want. Here I asked for inline HTML, especially for Azure Pipelines and Cobertura. This is how I got reporting to work.

If you notice testing framework assemblies and namespaces (in my case xUnit) in code coverage reports, then add set Assembly filter property of ReportGenerator task  to: -xunit*.* . Using similar patterns, it's possible to leave out also other unwanted assemblies.

Save the changes to a build pipeline and run it to make sure all the steps succeed and that there are also no warnings by the unit tests or report generator task.

Viewing Code Coverage Reports

If all the steps in pipeline succeeded then there will be a new link to code coverage reports in the header of the pipeline run (in red rectangle). It is shown there automatically if code coverage information is published correctly.Image title

When clicking on this link we can see a full code coverage report. We stay in the Azure DevOps environment, in the same view. Links shown in the report just work with Azure DevOps environment.Image title

The report is interactive and we can click on class names to see more specific details about code coverage.Image title

Reports like this are generated every time our build pipeline is run. If we make a build pipeline run on every commit to code repository, then we get code coverage reports for every build automatically.

Wrapping Up

We were already able to run code coverage reports on local boxes. Now we took it a step further and added code coverage reports to the Azure DevOps build pipeline. This way we make code coverage reports available for all commits and so those who don't bother to check reports locally can go and see their result on the build server.

Code coverage ASP.NET ASP.NET Core azure unit test DevOps

Published at DZone with permission of Gunnar Peipman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Are the Benefits of Java Module With Example
  • mTLS Everywere
  • Introduction to Container Orchestration
  • Getting a Private SSL Certificate Free of Cost

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: