January 28, 2013 by Anuraj
.Net Code coverage Visual Studio
If you are using VS 2012, by default Code coverage results are available for Test assembly also.
There is no direct way to disable this behavior, either you need to use the ExcludeFromCodeCoverage attribute or you need to use the runsettings file.
The ExcludeFromCodeCoverage is pretty straight forward; you need to decorate all the unit test classes with this attribute, like this
But this attribute only works in Class, Structs, Constructors, Methods, Properties and Events. So if you want to disable code coverage for an entire assembly this will not work.
The other option is using runsettings file. To use this VS feature you need to add a new file with .runsettings extension to the solution. Copy the XML content below and paste it to the .runsettings file.
Select the .runsettings file from Test > Test Settings > Select Test Settings file menu.
Now if you analyze the code coverage with the new runsettings file, only the code file assembly coverage will be displayed.
You can disable the use of .runsettings file by un-checking it in the Test Settings Menu item.
You can find more details about ExcludeFromCodeCoverage attribute in MSDN
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub