This is not very wide known feature in Visual Studio that has been there even in version 2005 but still there are not many articles on it.
When you try to get code coverage from functional tests then the default UI features in VS won’t help. This is because code coverage is measured only on referenced assemblies (from what I was able to understand). The steps below actually describe the process of collecting code coverage data.
In order collect code coverage information on service – could be remotely hosted WCF service, or local WCF service but hit through endpoint – following steps should be executed:
1. Instrument the assemblies – did you think that code coverage is that simple :). VsInstr.exe is the tool for that.
1: VsInstr.exe /coverage wcfService.dll
2. Deploy assemblies – This step means actually installing deployed instrumented assemblies on the IIS. On other side default WcfSvcHost.exe also can be used:
WcfSvcHost.exe" /service:%cd%\WcfService.dll /config:%cd%\WcfService.dll.config
3. Start VS monitor that collects data -this is separate tool - VSPerfCmd.exe. Sample usage is
VSPerfCmd.exe /start:coverage /output:”C:\CoverageData.coverage” /cs
4. Run your tests that hit the service.
5. Stop the monitor.
6. Open c:\CodeCoverageData.coverage in VS
Hope this helps…
Ops. Almost forgot. I wasn’t able to make it work on x64 bit machine. For this purpose I had to use x86 version of .. Windows, of course :) !
Here are some useful links: