Thursday, March 10, 2011

Blog Post: 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 Test.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

Tami Donaldson Padma Lakshmi Sarah Mutch Gabrielle Union Alessandra Ambrosio

1 comment:

  1. This is a nice article..
    Its very easy to understand ..
    And this article is using to learn something about it..

    c#, dot.net, php tutorial

    Thanks a lot..!

    ReplyDelete