Code coverage features in Visual Studio Enterprise

Faisal Hafeez

By using code coverage, you can find out where your testing needs improvement and make your software more robust and dependable. In this post, we will introduce the new features that we introduced to the Code Coverage Results window in Visual Studio Enterprise 2022. These features are: 

  • Support of additional report formats 
  • Enhanced report merging 
  • Performance enhancements 
  • Code coverage views 

These features are not available in Professional or Community editions of Visual Studio. 

Support of additional report formats 

We now support additional formats for coverage reports. The formats that are supported are as follows: 

  • Binary (default): .coverage (Microsoft special binary format) 
  • Cobertura: .cobertura.xml (Java code coverage tool XML format) 
  • XML: .xml (Microsoft XML format) 
  • CoverageXml: .coveragexml (Microsoft XML format) 

A coverage report can also be changed to other formats that are supported. Example 

Improved Report Merging 

We have changed how we merge reports. Now we combine projects in reports if they use the same source code. For example, if a project is targeting different frameworks, the merged report will have only one item for the project with the coverage data added together. 

Visual Studio Enterprise 17.5  Visual Studio Enterprise 17.9 
Image old merge Image new merge

See merge repots scenario for a full example. 

Performance Enhancements 

Coverage report operations have become faster over time. With the latest version of Visual Studio Enterprise Version, report merging and opening is significantly faster. 

The table shows how long it takes to open a report in different versions of Visual Studio. 

Visual Studio Enterprise Version  Time (sec)  Ratio 
16.5  54  1.00 
17.0  42  0.77 
17.5  11  0.20 
17.9  5  0.09 

And for report merging 

Visual Studio Enterprise Version  Time (sec)  Ratio 
17.0  47  1.00 
17.5  42  0.89 
17.9  6  0.12 

Coverage Views 

New views have been added in the coverage window to view the coverage data in diverse ways. They provide different perspectives to visualize coverage data and improve developer’s experience. 

Margin Glyphs 

We have introduced a new method of seeing coverage in the editor. Margin glyphs use solid rectangles in the margin to indicate covered lines, stripe rectangles to indicate partially covered lines, and open rectangles in the margin to indicate uncovered lines. 

Line Coloring (default)  Margin Glyphs 
Image line coloring Image margin glyphs

Visit example to turn on different code coverage coloring. 

Source View 

Source View displays coverage data based on directory/file structure rather than namespace/class/method structure. It merges coverage information at a file level. 

It is helpful when you have C++ code and unit test projects are using static libraries. For project view, each unit test project shows coverage only for the code run in their own tests. But source view combines coverage run for all test projects. 

Project View (default)  Source View 
Image project view report static Image source view report static

See report type view for a complete sample. 

Changeset Report 

Changeset report filters the coverage report and shows coverage statistics only for the changes made in current local git branch. It helps developers to identify coverage status of their own changes and improve code coverage of new code. 

Full Report (default)  Changeset Report 
Image full report Image changeset report

To see a complete example, look at the report content view. 

Search has been added to the code coverage results window. You can search using different search parameters to filter your report. For example, show methods where block coverage is less than 80%.

Image search

To see more options, check out search examples. 

You can use any combination of views together. For example, you can display only the methods that have less than 80% block coverage in your current branch. The coverage windows and the code editor will show the filtered results. 

Summary  

We are excited for you to use our new code coverage features. We believe that these features will help you in identifying and improving code coverage for your solution. 

We appreciate the time you have spent reporting issues/suggestions and hope you continue to give us feedback when using Visual Studio on what you like and what we can improve. Your feedback is critical to help us make Visual Studio the best tool it can be! You can share feedback with us via Developer Community: report any bugs or issues via report a problem and share your suggestions for new features or improvements to existing ones.   

Stay connected with the Visual Studio team by following us on YouTube, Twitter, LinkedIn, Twitch and on Microsoft Learn.  

Feedback usabilla icon