Setting Up NCover To Cover Your Web Apps
NCover collects coverage on your .NET web apps by profiling IIS. Specifically, NCover watches the w3wp.exe, the IIS worker process, in order to collect coverage. This approach allows you to automatically capture coverage once you have properly configured your project.
There are two basic methods for setting up a NCover project to cover IIS. Both methods are based on a common methodology and end with the same result. If this is your first time setting up a web service, we recommend the Auto-Configure method as it provides feedback that you have properly found the process to be profiled.
Create a new NCover project and select the Auto-Configure option. This will launch the Auto-Configure process.
Reset IIS so that NCover can attach to the w3wp process. It is important that this be done after the NCover project has been setup. NCover looks for processes to start in order to begin profiling. If the process was running prior to setting up the project, NCover will not detect it and will not be able to add it to the project.
Start your web application. You will see the executables and assemblies that are being detected. By default, they will all be covered. You can deselect items to cover or add additional filters to focus your code coverage. Save your project. You are now ready to begin collecting coverage the next time the application is restarted.
Create a new NCover project and, on the Filters tab, define a match rule like the example below to profile the .NET code of your web application:
Match type=”Regex”, Process matching=”w3wp”
This approach assumes your web app is running locally on IIS. If you are using IIS Express, the VS dev server, or another .NET web server, then you would use the appropriate process name instead of “w3wp”. At this point, NCover is ready to collect coverage. If you know specifically the modules you want to profile, you can define them at this point.
Reset IIS so that NCover can attach to the w3wp process. NCover looks for processes to start in order to begin profiling. If the process was running prior to setting up the project, NCover will not detect it and will not be able to collect coverage.
Start your web application. NCover will now collect coverage on the code that is exercised by your tests. You can stop or reset IIS to stop collecting coverage.
Regardless of the method you used to setup your project, collecting coverage on a going forward basis is the same. Simply reset IIS at the beginning and end of your web testing to start and stop collecting coverage. As long as the NCover project is setup to collect coverage and enabled, profiling will be automatically started and stopped with the reset of IIS.