StudioTools: Code Coverage
Unit tests are for testing your application code, code coverage is for testing your unit tests. Without some way to track your code coverage, it's difficult to determine if your application has adequate testing. The StudioTools code coverage feature help you improve the quality of your code by making it easy to determine which lines and methods are not fully covered by automated unit tests.
While high coverage is no guarantee of good tests, anything less than 100% coverage is a sure sign that you have untested code. This then becomes your target, a goal to work against as you develop your tests. Integrating code coverage into unit testing practices helps you figure out when you are really finished, and helps you see if you code has drifted away from your tests over time as tiny changes sneak in without a corresponding test.
Track your coverage while you test
StudioTools's code coverage features help ensure proper levels of coverage throughout your solution by automatically tracking coverage each time your run your unit tests. Solution level coverage information is displayed in the Coverage Profiler panel as well as the editor itself, and includes line, method, and class level coverage statistics.
Editor highlighting to see what you're missing
Code coverage information is displayed directly in the code editor. Any lines of code not covered by your automated unit tests will be marked with a red bar, making it easy to know what you are missing. You can also elect to view positive coverage information, that is the lines that were hit during by the tests, by enabling the Show Hit Lines option. Positive coverage markers will also provide profiling information such how many times the lines was hit, how long it took, and how much memory was used. Just hover your mouse over a coverage marker to learn more.
Analyze coverage across the entire solution
The Coverage Profiler panel provides aggregate coverage information across the entire solution. It provide coverage statistics at the solution, namespace, class, method, and line levels. Results are presented in a sortable list view. Click on the class names to jump into the editor where you can examine line level coverage markers. A tolerance slider lets you hide tests with an acceptable level of coverage, so that you can focus on the worst offenders. For example, if you are shooting for 80% coverage set the tolerance slider and the list will only include classes with worse than 80% coverage.
Export coverage results as XML
You can export your application's coverage information in XML format. This makes it easy to generate coverage reports, track coverage over time, and collect other metrics. From the Coverage Profiler's file menu, just select .
Fully configurable color schemes
If you would prefer a different color scheme, you can choose your own colors from the StudioTools section of the Visual Studio options panel. This is especially helpful if you suffer from red/green color blindness!