Setup OpenCover with IIS
Hi,
I'm trying to setup OpenCover to profile assemblies running in IIS. I can't find documentation on how to set up the console parameters.
e.g. I have some assemblies + .pdb files in C:\inetpub\wwwroot\MyWebSite\bin which runs as a separate webapp.
I want to start coverage, run some tests on IIS (e.g. through the browser), and then stop coverage. Is this scenario possible?
can you provide any help on this? regards, Jerry
Do you have to run in IIS?
Though OpenCover can be used to get results against a service like IIS, I have found that trying to run coverage against IIS very problematic (please also bear in mind I think this is the wrong thing to do and you should be using a unit testing framework like nunit or mstest to get coverage data).
Personally if I have to do coverage of a web application whilst hosted then I use a developer hosting tool such as IIS Express. As this utility can be run from the command line I find it much easier to automate.
Thanks for your reply. After fiddling and googling around a bit I actually managed to get it working!!
Altough code coverage is used typically in unittesting scenarios, I think you'd be happy to hear that in fact you can use OpenCover on an actual internet server (IIS) effectively.
I prefer to run (automated) tests against a production like environment. E.g. Unit tests do not/cannot test codebehind. Therefore running code coverage on an actually running website is in fact a broader/more in depth coverage.
The trick is to start OpenCover to run the w3wp.exe process in debug mode. e.g.
OpenCover.Console.exe -target:C:\Windows\System32\inetsrv\w3wp.exe -targetargs:-debug -targetdir:C:\Inetpub\wwwwoot\MyWebApp\bin\ -filter:+[] -register:user
There are some prerequisites tho:
- all applications running under the site must make use of the same app pool. you'll get errors in the eventlog otherwise.
- inetserver needs to be stopped, before starting w3wp.exe in debug mode. You can use the following command:
net stop w3svc /y
- after testing/code coverage completion you can close the w3wp.exe proces and start the inetserver again:
net start w3svc
This procedure was tested on a Win2008 machine with IIS7.5
OK well, maybe I'm using the tool not exactly as intended, however I'm happy to report that in fact this setup does work for me and will be integrated into our continuous integation.
cheers, Jerry
Excellent - I'll add this to the documentation
Hi, I would like to understand where the output of coverage results store after the Opencover closed. Thanks, Amanda
In the Usage section of the wiki it says
-output:<output file> - The location and name of the output Xml file. If no value is supplied then the current directory will be used and the output filename will be results.xml.
If in doubt supply the pathname and specify it exactly where and what you want to call the output file
Hi Shaun, Thank you for getting back. I now got the output but it is not the output I am looking for. See below testcases I tried and their outputs. Run against IIS to test SOAPUI.
All the testcases below ran from remote powershell with the following tested commands:
case 1
$OpenCoverPath "-target:C:\Windows\System32\inetsrv\w3wp.exe", "-targetargs:"-debug -s $websiteId"", "-targetdir:$WebAppPath", "-output:$Output"
output C:\testfolder\OpenCover-Output.xml
case 2 I googled and saw suggestion to add "-register:user". I did as the command below:
$OpenCoverPath "-register:user", "-target:C:\Windows\System32\inetsrv\w3wp.exe", "-targetargs:"-debug -s $websiteId"", "-targetdir:$WebAppPath", "-output:$Output"
OUtput C:\testfolder\OpenCover-Output.xml
The OpenCover-Output.xml file did not generate at all. The file wasn't not found in the c:\testfolder folder
Do you know why? Does w3wp.exe require special admin permission? If yes, how to configure?
The remote machine is 2003 SP2, IIS6, Do I need to make sure to configure IIS website correctly inorder to work with Opencover?
case 3 I added this option "-mergebyhash", but it didn't help.
$OpenCoverPath "-register:user", "-target:C:\Windows\System32\inetsrv\w3wp.exe", "-targetargs:"-debug -s $websiteId"",
"-targetdir:$WebAppPath", "-output:$Output", "-mergebyhash", "-filter:+[test.]"
output C:\testfolder\OpenCover-Output.xml
The OpenCover-Output.xml file did not generate at all. The file wasn't not found in the c:\testfolder folder
Please advise if anyone got it to work by running against IIS.
Thanks in advance, Amanda
Hi Amanda
I only know what Jerry (Dinohj) supplied as how he got it to work. As I said I use IIS Express to test against web sites rather than IIS as it is much easier to control and was supplied for this exact purpose. Whether this is subtle for you development/testing environment I cannot say.
The remote machine is 2003 SP2, IIS6, Do I need to make sure to configure IIS website correctly inorder to work with Opencover?
Are you running OpenCover and IIS (website) on the same machine - OpenCover does not run against a remote machine and can only gather coverage on code executing on the same machine as itself.
The OpenCover-Output.xml file did not generate at all. The file wasn't not found in the c:\testfolder folder
What was the output on the screen?
Shaun
The same output I provided you if option no "-Register:user" is used, i got the below output:
BTW, the SOAPUI test cases all failed with the error below:
Response Headers: X-AspNet-Version : 4.0.30319 Date : Fri, 01 Nov 2013 19:41:22 GMT #status# : HTTP/1.1 500 Internal Server Error Content-Length : 608 Content-Type : application/soap+xml; charset=utf-8 X-Powered-By : ASP.NET Server : Microsoft-IIS/6.0 Cache-Control : private
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> soap:Body soap:Fault soap:Code soap:Valuesoap:Receiver/soap:Value /soap:Code soap:Reason <soap:Text xml:lang="en">Server was unable to process request. ---> Failed to create AppGlobals. The ConnectionString property has not been initialized. ---> The ConnectionString property has not been initialized./soap:Text /soap:Reason soap:Detail/ /soap:Fault /soap:Body /soap:Envelope
As for for scenario with argument "Register:user", the coverage.xml wasn't able to generate at all.
Thanks and best regards, Amanda
Hi Shaun, I just ran again with "-register:user", all my test cases failed with the command below: Do you have any idea?
"- missing response / garbage collected -"
Thanks, Amanda
That isn't an OpenCover message - it looks specific to SoapUI (http://forum.soapui.org/viewtopic.php?f=2&t=18577) see http://www.massapi.com/source/soapui-4.0.0/src/java/com/eviware/soapui/impl/wsdl/teststeps/WsdlTestRequestStepResult.java.html line 233).
If you can supply a repeatable scenario I can attempt to investigate
Shaun, Thank you so much for all your help! You are correct, the problem now is on Soapui not OpenCover anymore. All these utilities are new to me and when all happened, I don't seem to be able to narrow down exact application that caused the issue, right away. Thanks again, Amanda
What does it mean run w3wp.exe in debug mode? what is the different between the work process in debug mode and the process managed by WAS ?
Also see (http://stackoverflow.com/questions/25238859/what-does-it-mean-start-a-worker-process-w3wp-exe-in-debug-mode)
According to http://support.microsoft.com/kb/183480 it switches the security context of the running user which is not its normal mode of operation
Tried to profile IIS ON WIN 10 Machine. Basically not able to get the website working when using open cover( getting forbidden:18) any ideas?
@hghanta please don't resurrect old 'closed' issues - please raise new ones and follow the instructions - thanks