Covering IIS

Covering IIS in NCover 4 is fundamentally the same as profiling any other .NET process, but because of the way IIS runs, profiling this service presents some special challenges.

1. Project Settings

Finding the right process to profile is the key to successful coverage. Profiling is accomplished with match rules, so let’s talk about how they work for IIS and the options for creating them.

From the Home view of the NCover 4 Explorer, click Add New to open the “Create a New Project” window.

From the “General Settings” tab, name your project.

In the Processes to monitor section, specify a Type and a Value to create a Match Rule for the IIS process.

Users sometimes make the mistake of specifying a test DLL as a match rule. Remember that NCover needs to be able to profile the process that is loading your tested assemblies, in this case, the w3wp worker process.

With this in mind, a regex like “w3wp” is a good way to catch the worker process whenever it runs locally.

2. Auto-Configure

Another option is to click on the Auto-Configure button and let Desktop create match rules for you.

Auto-configure

The General Settings tab will switch to the auto-detect view and start monitoring for .NET processes as soon as you click on Auto-Configure.

Note: A common stumbling-block for users trying to cover IIS is the fact that a w3wp process already running in the background is easy to miss.

The NCover profiler needs to be able to attach to a process when it starts (whether this is IIS or a test runner). So, before testing web apps, you should reset IIS so that the NCover profiler can attach to the w3wp.exe as it initializes.

After you reset IIS, start your web application and exercise your code (manually or with unit tests).

The modules that are being loaded by your testing will display in the detection window.

Desktop IIS auto-detect

Review the list of modules detected and uncheck any modules that shouldn’t be covered.

Click Stop Detection when your selections are complete.

Click Show Match Rules to view the settings that NCover created based on the .NET code that was loaded during your testing.

Desktop IIS auto-generated Match Rule

This Exe match rule will cover IIS whenever it runs from the specified path.

You can change this path match rule to a regex instead, which will monitor the w3wp process regardless of where it runs.

Desktop IIS regex

Click Save to accept these selections.

Note: “Include” filters will be automatically created based on the modules that you selected. You can review the filters on the “Pre-Coverage Filter” tab.

Desktop IIS Pre-Coverage filter

3. Collect Coverage

When your auto-configure and filter selections are complete, save your project settings.

Note: Before running your web app, remember to reset IIS.

Start your web application. Go to the Home page and you’ll see that the light beside your project is pulsing green to indicate coverage is being collected.

Immediately to the right of your project name, the Modules Collecting counter displays the number of modules being profiled.

When your tests are complete, close your web application.

Note: Don’t forget to stop or reset IIS to end the w3wp process that NCover is profiling.

This will stop profiling and NCover 4 Desktop will collect and aggregate the coverage data.

Profiling IIS in Desktop uses the same principles as any other kind of coverage, but the IIS environment requires some additional input from the tester to make covering web applications successful.