How can I disable code coverage / assembly instrum

2019-05-22 22:57发布

问题:

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?

回答1:

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.



回答2:

Code coverage is only enabled through the Test Explorer using data driven adapters. The metadata for tests ran through the test explorer is almost completely different than that of tests ran straight from the unit test session window. Have you tried simply running it straight from the code (the MSTest gui bubbles) or from the unit test session window?