다음을 통해 공유


C# Code Coverage using VS2010

This is Syed Aslam Basha here from Information security and risk management team.

Code coverage describes the degree up to which the source code of the program has been tested. The process would involve setting up code coverage and testing the entire application.

Preconditions

You should have pdb files for the DLLs and deployed the bits

Steps to setup code coverage

  • Open command prompt in privileged mode
  • Change the directory to \Program Files\Microsoft Visual Studio 10.0\Team Tools\Performance Tools\ or C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Performance Tools\x64 for X64 bit setup (OS and VS)
  • Instrument application dlls by running the command vsinstr -coverage “…\abc.dll” (Dlls are usually found in bin directory). This step will create backup of original DLL with .orig extension and instruments the dll
  • Start coverage monitor by running the command \Program Files\Microsoft Visual Studio 10.0\Team Tools\Performance Tools >start vsperfmon -coverage -output:"D:\xyz.coverage" /CS /user:everyone
  • Run your tests(unit test cases/ CUIT /manual) pointing the instrumented bits
  • Stop the coverage monitor by running the command vsperfcmd /shutdown
  • Open the file xyz.coverage to find your code coverage results.
  • The code coverage results would look like, it shows 80% code coverage and 20% code is not covered
  • image

 

- Syed Aslam Basha ( syedab@microsoft.com )

Microsoft Information Security Tools (IST) Team

Test Lead

---------------------------------------------------------

Please leave a comment if the blog post has helped you.

Comments

  • Anonymous
    September 07, 2011
    Hi, Where to find the Xyz.coverage file.. Please let me know.. My Email ID: addy369k@gmail.com Thanks, Adi.

  • Anonymous
    September 18, 2011
    The coverage file will be in the path specified in -output switch Syed

  • Anonymous
    April 22, 2014
    I'm using Fitnesse applied to C# and it worked perfectly. Thank you Syed, Heitor