Covering IIS & Your .NET Web Apps

Setting Up NCover To Cover Your Web Apps

Covering IIS with NCover

NCover's approach to covering IIS, through the use of pre-coverage filters, provides a dynamic method for collecting coverage from both automated and manual tests

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.

The Process of Covering IIS

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.

Both approaches require IIS to be restarted
after the NCover service is running

Restarting IIS allows NCover to attach to the w3wp.exe process. We recommend using the "iisreset" command. If you do not reset IIS, NCover will not be able to detect the service and collect coverage.

The "Auto-Configure" Method

Step One

Create a new NCover project and select the Auto-Configure option. This will launch the Auto-Configure process.

Step Two

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.

Step Three

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.

The "Manual" Method

Step One

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.

Step Two

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.

Step Three

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.

Going Forward

Starting and Stopping

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.

.NET Code Coverage Solutions For Improving Code Quality