DCSIMG
Manually Configure and Run code Coverage - Roy Rosenberg

Roy Rosenberg

Team System and ALM Consultant

Manually Configure and Run code Coverage

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

VSInstr.exe

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)

VSPerfCmd.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

 

 

Posted: Aug 30 2011, 12:31 PM by RoyRose | with 2 comment(s)
תגים:

Comments

SharePoint Memory Dump said:

I spent almost 10 hours yesterday to figure out how to run SharePoint unit tests using VS 2010 and how

# September 17, 2011 11:04 PM

SharePoint Visual Studio Unit Tests and Code Coverage - MSDN Blogs said:

Pingback from  SharePoint Visual Studio Unit Tests and Code Coverage - MSDN Blogs

# September 18, 2011 3:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: