C# Code Coverage using VS2010

C# Code Coverage using VS2010

  • Comments 2

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
  • Hi,

    Where to find the Xyz.coverage file..

    Please let me know..

    My Email ID: addy369k@gmail.com

    Thanks,

    Adi.

  • The coverage file will be in the path specified in -output switch

    Syed

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 2 and 5 and type the answer here:
  • Post