The code coverage tool in Visual Studio 2008 Team System is quite easy to use from within the IDE unless you want code coverage for your native C++ code. In order to generate a code coverage report for native C++ you have to use the command line tools. This is how you do it:
- First of all your project must be compiled using the /PROFILE link option. If you bring up your project properties it can be found here:
Configuration Properties -> Linker -> Advanced -> Profile
- The profiler tools can then be found in the following directory:
C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools
- You need to add some instrumentation code to your EXE or DLL file and that is done with this command:
vsinstr.exe <YOUR_EXE_OR_DLL> /COVERAGE
This will copy the original file to an ".orig"-file and create a new file with the original name that contains instrumentation code needed to gather coverage data.
- Now start the listener with this command:
VSPerfMon.exe /COVERAGE /OUTPUT:<REPORT_FILE_NAME>
- Now run your EXE or some test suite that uses the file you want to calculate coverage for.
- The listener started in step four (4) will not stop by it self once your test suite is finished so you have to stop in manually using this command (from a second command prompt):
- When the listener has stopped you just drag-n-drop the created ".coverage"-file into Visual Studio and you can view the results.