Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 Code Coverage

We have very complex web based product including solid number of web services etc. I'm trying to collect code coverage for all assemblies in our product using VS 2012 command line utility vstest.console.exe. It is pretty easy to collect code coverage for Unit Tests, however, there is no flag or switch that indicates that I can attach the process to IIS or collect info for web services (both client and server sides).

Any suggestions?

like image 300
monkzen Avatar asked Dec 10 '12 22:12

monkzen


People also ask

How do I get code coverage in Visual Studio?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.

How do I check my code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

How do I enable code coverage?

Enable code coverage on your project. Right-click your project and select Properties > Code Coverage. Select Enable code coverage. Click OK.

Does Visual Studio Professional have code coverage?

Microsoft Visual Studio Enterprise 2022 has code coverage feature, nevertheless i prefere Fine Code Coverage. Professional doesn't have code coverage built in.


2 Answers

Detailed instructions for collecting code coverage from IIS applications using Microsoft Test Manager(MTM) of Visual Studio 2012 Update 1 can be found in this blog: http://blogs.msdn.com/b/visualstudioalm/archive/2012/11/28/code-coverage-in-microsoft-test-manager-in-visual-studio-update-1.aspx

Here is the summary:

  • Install VS Update 1.
  • Connect Microsoft Test Manager(MTM) to a Team Project (Team Foundation Server) and setup test plan etc. You can utilize the free account in Team Foundation Service to create team project.
  • Create a test settings with code coverage data collector enabled.
  • Run a manual test or an exploratory test with this test settings.
  • You will get the code coverage file at the end of the test run.

Alternate solution:

  • Use CodeCoverage.exe to collect code coverage. Path: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe. You don't need update 1 to be installed, but I recommend that you do so. Example:

    CodeCoverage collect /IIS /session:WebSession /output:MyWebApp.coverage

like image 93
Hardik Avatar answered Nov 23 '22 22:11

Hardik


From the toolbar menue at the top: TEST > Analyze Code Coverage > All Tests

The results show up in the Code Coverage Results window. TEST > Windows > Code Coverage Results

I have VS2012 Premium, not sure if this feature is in other tiers.

like image 43
GraehamF Avatar answered Nov 23 '22 20:11

GraehamF