How to generate Code Coverage Results for WCF services in VSTS 2010
-
Wednesday, January 12, 2011 3:31 PM
We are using WCF Service in the application and the application is hosted in IIS locally. We have Service layer which has all the functionality and and the WCF wrapper around the service layer. We wrote some tests for the functionality in the service layer which call WCF services through proxy. When we tried to generate Code Coverage results for the Tests in the service layer we found incorrect results being generated. I also tried using tools like VSinstr and VSPerfCmd to generate results.
If I instrument only my service.dll the coverage results using the tools says: Empty results generated: none of the instrumented binary was used.
Then I tried to instrument both my Service.dll and Service.WCF(wrapper).dll then I got the same results which my Visual studio gave me(100 % not Covered).
I followed the following steps:
- Instrument the web service binary that you want coverage on: VsInstr.exe /coverage myWebService.dll but did'nt deploy the service as it is already hosted in local IIS.
- Start the monitor for collecting coverage data: VSPerfCmd.exe /start:coverage /output:”C:\CoverageData.coverage” /cs
- Run the scenario or test cases that will exercise the WCF service(Service.Tests).
- Shut down the monitor when the tests are done.
Could you please help me in trying to get Code Coverage Results.
Thanks in advance.
Swathi.
Swathi
All Replies
-
Thursday, January 13, 2011 10:24 PM
Hi,
You are getting no code coverage since your tests are not hitting the instrumented dlls. Instead, they are hitting the already deployed unistrumented dlls in IIS.
You should stop IIS and deploy the instrumented dlls and then start IIS again in step 1
Also, you should pass the argument /user:"Everyone" to vsperfcmd in step 2
Refer http://blogs.msdn.com/b/phuene/archive/2007/05/14/code-coverage-collection.aspx
Thanks,
Anuj
-
Monday, January 17, 2011 8:40 AMHi,
Thanks for the response.
I tried changing my steps as you suggested but I still get the same error saying Empty Results generated: none of the instrumented dll's are used.
Here are the steps I followed:
1. Stopped IIS and instrumented both my Service.dll and WCFWrapper.dll. And then started my IIS again.
2. Start the monitor for collecting coverage data: VSPerfCmd.exe /start:coverage /output:"C:/CoverageData.coverage" /cs /User:"Everyone".
3. Run the scenario or test cases that exercise the WCF service (Service.Tests).
4. Shut down the monitor when tests are done.
Please let me know where I am going wrong.
Thanks,Swathi
Swathi -
Monday, January 17, 2011 10:14 AM
I have the same problem follow the same steps in win2008 r2.
help!!!
-
Monday, January 17, 2011 10:21 AMI have no idea that is because of http layer?
-
Wednesday, January 19, 2011 4:25 AM
Hi,
I was able to reproduce your issue and found the solution. You will see empty results generated if your browser has cached any previous requests. Hence you should open a new browser window when you run your tests. Here are the steps I followed:
1) Stop IIS by using the command iisrest /stop
2) Copy the binaries along with the symbols in the expected virtual directory
3) Open visual studio command prompt and instrument the binaries by using the command vsinstr /coverage ".dll"
4) Start IIS by using the command iisrest /start
5) Start code coverage monitor by using the command vsperfcmd /start:coverage /output:"CoverageDa
a.coverage" /cs /User:"Everyone"6) Open a new browser window and run your tests
7) Stop coverage monitor by using the command vsperfcmd /shutdown
8) You will see the message "Waiting for process 6276 ( c:\windows\system32\inetsrv\w3wp.exe) to shutdown..."
9) Stop IIS by using the command iisrest /stop
10) Open the coverage file to view the results.
Here are the logs:
C:\inetpub\wwwroot\Calculator\bin>iisreset /stopAttempting stop...
Internet services successfully stoppedC:\inetpub\wwwroot\Calculator\bin>vsinstr /coverage App_Code.dll
Microsoft (R) VSInstr Post-Link Instrumentation 10.0.30319 x86
Copyright (C) Microsoft Corp. All rights reserved.File to Process:
C:\inetpub\wwwroot\Calculator\bin\App_Code.dll --> C:\inetpub\wwwroot\Calcula
tor\bin\App_Code.dll
Original file backed up to C:\inetpub\wwwroot\Calculator\bin\App_Code.dll.origSuccessfully instrumented file C:\inetpub\wwwroot\Calculator\bin\App_Code.dll.
C:\inetpub\wwwroot\Calculator\bin>vsinstr /coverage App_Web_2ieciz5m.dll
Microsoft (R) VSInstr Post-Link Instrumentation 10.0.30319 x86
Copyright (C) Microsoft Corp. All rights reserved.File to Process:
C:\inetpub\wwwroot\Calculator\bin\App_Web_2ieciz5m.dll --> C:\inetpub\wwwroot
\Calculator\bin\App_Web_2ieciz5m.dll
Original file backed up to C:\inetpub\wwwroot\Calculator\bin\App_Web_2ieciz5m.dl
l.origSuccessfully instrumented file C:\inetpub\wwwroot\Calculator\bin\App_Web_2ieciz5
m.dll.C:\inetpub\wwwroot\Calculator\bin>iisreset /start
Attempting start...
Internet services successfully startedC:\inetpub\wwwroot\Calculator\bin>vsperfcmd /start:coverage /output:"CoverageDat
a.coverage" /cs /User:"Everyone"
Microsoft (R) VSPerf Command Version 10.0.30319 x86
Copyright (C) Microsoft Corp. All rights reserved.C:\inetpub\wwwroot\Calculator\bin>vsperfcmd /shutdown
Microsoft (R) VSPerf Command Version 10.0.30319 x86
Copyright (C) Microsoft Corp. All rights reserved.
Waiting for process 11372 ( c:\windows\system32\inetsrv\w3wp.exe) to shutdown...Shutting down the Profile Monitor
------------------------------------------------------------C:\inetpub\wwwroot\Calculator\bin>
Thanks,
Anuj
-
Thursday, January 20, 2011 4:15 AM
Hi guys,
Thanks for your solution!!!
Since my environment is windows2008 r2 and iis7, so there is an important step should be done before step 6: You should update the properties of the AppPool running your app. Right click on the AppPool running your application under test and select Advanced Settings. Change the value of Enable 32-Bit Applications to True.
and then the coverage data would be collected!
Just share for you.
-
Friday, January 21, 2011 8:17 AM
Hi guys,
Thanks a lot for the solution and detailed explanation.
But could you please be still more clear.
My application is already hosted in local IIS but by giving a virtual path and is not present in the C:/inetpub/wwwroot as you said.
I instrumented the dll's from the path which is used to host the website in IIS.
But my test.dll is not present in the hosted website. I ran the test in visual studio or using mstest. And I really do not understand how to run tests in the browser.
I never got a message saying waiting for process so and so...
I am also using IIS7 and changed my AppPool settings.
Please help me to in getting code coverage results.
Swathi -
Friday, January 21, 2011 10:31 AM
Hi guy,
If you got a message saying waiting for process, that means you have attach the w3wp.exe and what you just need done is shutdown the iis, and the code coverage would be generaged.
-
Saturday, January 22, 2011 6:23 AM
Hi,
Did you follow my above steps carefully. You virtaul directory doesnt nexcessary has to be in c:\inetpub\wwwroot. It can be anywhere on your drive. You test.dll doesnt need to be present in the hosted website.
Do you know the url of your wcf service along with the expected parameters. Try hitting that url in IE by opening a new window. If you are able to get some numbers for code coverage then you are on the correct path.
Thanks,
Anuj
-
Wednesday, January 26, 2011 2:09 PM
Please see the following
Make sure to set up the environment variables that tell .NET to load our profiling helpers and reboot the machine
Off Road Profiling of ASP.NET Applications
http://blogs.msdn.com/b/graycode/archive/2005/05/10/aspnetoffroadprofilingarticle.aspx
Thank you ~
bill boyce- Proposed As Answer by billb08 - MSFT Wednesday, January 26, 2011 2:09 PM
- Marked As Answer by Hongye Sun - MSFTModerator Tuesday, February 15, 2011 7:59 AM
-
Wednesday, November 02, 2011 12:08 PM
Hello,
I'm trying out your solution, only difference is that I'm trying it with IIS Express.
The assemblies in the code I'm trying to get coverage data from are fully signed with a SNK.
When running the automated tests, after doing the vsinstr/vsperfcmd, all the tests fail with an error such as:
Could not load file or assembly 'my assembly' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key.
I am assumind this is because of the changes done by vsinstr, which unfortunatelly doesn't seem to have a command line option to resign or similar.
Any ideas?
thanks,
-jota
-
Wednesday, November 02, 2011 12:20 PM
Hello,
I answered myself: I re-signed the assemblies I instrumented, using SN -R, and it's now working.
Thanks anway.
-jota
-
Monday, April 23, 2012 6:08 AM
Hi
I am using Win 7 X-64 OS and IIS7.0. Observed same on Win 2k8, IIS7.0.
I am trying to get code coverage for WCF Service which is wrapped in a website application. My project structures is as follows:
MyCalc: WCF class library project
MyCalcServiceSite: It is a wrapper for WCF Lib proj. This project is created so that I can host WCF Services on IIS.
CalcTestProject: This is a test project which references MyCalc dll as project reference. When I run tests in this project, I CAN get the code coverage data.
CalcTestProjWCFReference: This is a test proj for which I added the service proxy class (created the proxy class) using SvcUtil.exe. If I run the tests in this project, I am NOT getting code coverage data. When I look at the codecoverage file, I see:
Empty results generated: none of the instrumented binary was used. Look at test run details for any instrumentation problems.
I followed the below steps to get code coverage for either of the Test projects:
1. vsperfclrenv /globaltraceon ( One time task: reboot machine after this setting)
- Host the MyCalServiceSite on IIS 7.0. Make sure that the service methods are accessible using the URL: http://localhost/MyCalcServiceSite/CalcService.svc
2. Stop IIS.
3. Instrument dlls that are deployed in physical path of the CalcServiceSite deployment folder: C:\CC\WebSites\MyCalcServiceSite\Bin. (command: vsinstr /coverage MyCalc.dll). Instrumentation is successful. Original dll is renamed to: MyCalc.dll.orig
4. Add “Everyone” to the drop the folder. Give read\Write permissions.
5. Start IIS
6. Start monitor (vsperfcmd /start:coverage /output:mycover.coverage /User:"Everyone")
7. Run tests from the test project path: C:\CC\MyCalc\CalcTestProjWCFReference\bin\Debug (command: mstest.exe /testcontainer:CalcTestProjWCFReference.dll)
8. Stop monitor(vsperfcmd /shutdown)
9. Observe that mycover.coverage file is generated. But when I view the contact I see the message:
Empty results generated: none of the instrumented binary was used. Look at test run details for any instrumentation problems.
10. At step 7, if I run the tests from the other test project: CalcTestProject (where MyCalc is added as a proj reference), I am successfully getting the code coverage.
Please let me know what I am missing here??
Vekat Koti
- Edited by Sadineni Venkata Koti Monday, April 23, 2012 6:09 AM

