Manually Configure and Run code Coverage

30 באוגוסט 2011

no comments

There is an option to configure and run code coverage manually for running manual tests such as test cases with Microsoft Test Manager. It can be done with few command line actions that need to be run. Here are the actions:

·         Run VSInstr.exe to replace the DLL\PDB files with the instrumented ones

·         Run VSPerfCmd.exe to start the code coverage

·         Run VSPrefCmd.exe to stop code coverage


In order to instrument our DLL(s), let's run the command(s):

      ·         VSInstr.exe "AssemlbyFile.dll" /coverage

After running, you can see that VSInstr.exe created the following files:

·         AssemblyFile.dll.orig

·         Assembly.Instr.pdb

Actually, VSInstr renamed the original AssemblyFile.dll to AssemblyFile.dll.orig and created new instrumented AssemblyFile.dll (See its size – much larger…)

Also, it created an instrumented pdb.

Note: You can run VSInstr command multiple times for each assembly (DLL\EXE)


To start logging the coverage, we use VSPerfCmd command with start\shutdown arguments:

      ·        VSPerfCmd.exe /start:coverage /output:Test.coverage

That's it! Now we are ready to run our tests. When finished, we need to shutdown the coverage action:

·         VSPerfCmd.exe /shutdown

You can look and find coverage file (in our case Test.coverage), just drag it to Visual Studio and it'll open in the Code coverage Window.

Important: usually, you can open Visual Studio Command Prompt and run the commands from there, but if you are on 64bit machine, the Test.Coverage file will be empty and you might get this error:

"Empty results generated: none of the instrumented binary was used"

That's because you need to run the command from x64 folder:

·         For x32 the folder is: <VSDir>\ Team Tools\Performance Tools

·         For x64 the folder is: <VSDir>\ Team Tools\Performance Tools \x64

I've create a small console application that loads all information from XML files and executes the commands above, it may help if you have more than one assembly to instrument and instead of running the VSInstr action multiple time, you can just update the XML and run the app. Here it is have fun



Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>