web analytics

Code Coverage – Combining IIS and Test Process numbers

At Composable, we are strong proponents of incorporating Continuous Integration into our development process, which entails running comprehensive test suites on every code change we make. As part of our commitment to quality, we continuously strive to enhance our Code Coverage metrics. Code Coverage measures the proportion of code that is exercised by the test suite, giving us valuable insights into the effectiveness and thoroughness of our testing efforts.

Improving Code Coverage is a key objective for us as it helps identify areas of code that may require additional testing or refactoring. By achieving higher Code Coverage, we can gain confidence in the reliability and stability of our software, ensuring that it meets the highest standards of quality.

To enable Code Coverage during a test run, you need to use the switch “/Enablecodecoverage” on the vstest.console.exe process.  We also configure our run settings file to exclude things like auto-generated code, and only include our assemblies.

Note that we have CollectAspDotNet option set to false. If true, this option will restart IIS for you, and add a code coverage collector on the w3wp.exe process. However, when the collector combines the results with what’s been collected in vstest.console.exe, it will not combine the two, and vstest.console.exe will TRUMP the results for any assemblies loaded in the same processes.

To circumvent this, we started the IIS code coverage ourselves using the below command

Note that the config file for CodeCoverage is similar to the run settings, but is not the exact schema.

To Stop the code coverage, you can do:

When publishing your test results, also include the IISCodeCoverage folder, and VS Online will include these results in the overall numbers and final coverage file.