How can I disable code coverage / assembly instrumentation in Visual Studio 2012?

Warren Rox picture Warren Rox · Nov 9, 2012 · Viewed 13.4k times · Source

I have a project upgraded from Visual Studio 2010 to 2012 and the .testrunconfig file was included in the upgrade process.

I noticed that it was possible to click "Analyze code coverage" on any of the unit tests that I had run and it would correctly display the result. However, my test run configuration (originally from VS 2010) had code coverage disabled.

After doing a bit of research I learned that the VS 2010 configuration files have been deprecated and replaced by .runsettings files. It would appear that VS 2012 enforces assembly instrumentation by default which has a massive overhead associated with it.

Therefore, I would like to know how I can disable code coverage in VS 2012. Based upon my current findings it does not seem to be a trival task. One recent article I read had me creating an XML file manually and naming it "MYCONFIGURATION.runsettings" and manually manipulating XML attribute values.

Does anyone know how this should be done?

Answer

Hardik picture Hardik · Nov 12, 2012

This is what I understand from your post:

  • You have a Test project with .testsettings file. You have not enabled code coverage in the test settings.

Code coverage instrumentation is not enabled by default in your scenario. Binaries will be instrumented if you do 'analyze code coverage' from VS.

Additional Info: You can confirm that .coverage file is not generated by running the following command from visual studio developer command prompt:

vstest.console.exe /Settings:<your test settings file> test.dll

A coverage file will only get generated if you have enabled coverage in test settings.