Getting code coverage in visual studio 2010 when using

Recently I set up a project where i wanted to use as a unit test framework and I also wanted code coverage so I thought it should be easy using VS2010. Even though the final solution turned out to be fairly simple there were a few bumps on the road. basically I had to do a variant of what I did for native coverage before. Basically I ended up with a batch file looking like this:

@echo off
del *.dll *.orig *.pdb *.exe *.config *.coverage
copy ..\ProjectUnitTests\bin\Debug\*.dll .
copy ..\ProjectUnitTests\bin\Debug\*.pdb .
copy PATH_TO_XUNIT\xunit.console.exe .
copy PATH_TO_XUNIT\xunit.console.exe.config .
copy PATH_TO_XUNIT\xunit.runner.utility.dll .
vsinstr.exe ProjectAssemblyTested.dll /COVERAGE
start vsperfmon.exe /COVERAGE /OUTPUT:Project.coverage
xunit.console.exe ProjectAssemblyTested.UnitTests.dll
vsperfcmd.exe /SHUTDOWN
call Project.coverage
@echo on

The only real bump in the road was that the error message when I used x86 profiler on a x64 assembly did not say anything meaningful. It just refused to gather any coverage data. So the trick was to open a VS2010 x64 command prompt and then everything worked smoothly. Easy enough to get coverage after all.

Comments (1)

  1. Daniel says:

    Thanks for this little script, it works great!

Skip to main content