Posted by Anuraj on Monday, January 28, 2013 Reading time :1 minute
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