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Â |
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 |
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 |
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 |
To see a complete example, look at the report content view.Â
SearchÂ
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%.
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. Â