Covering NUnit
NCover Desktop runs as a service, so it's already monitoring, ready to cover any .NET code executing on your machine.
This ability to gather data globally is key to understanding how to leverage the power of NCover Desktop. When setting up any project the first question you should ask is, What process do I want to cover? If NCover can find the executable or service that's exercising your code, it can collect coverage data.
Creating a Project
From the Home, or Project, view of the NCover Desktop, click Add New to open the "Create a New Project" window.
Match Rules
Finding the right process to profile is the key to successful coverage. Profiling is accomplished with match rules, so let's see how they work and the options for creating them.
When the "Processes" tab displays, name your project and then select one of two methods to specify the processes to be covered.
Note: If you're setting up coverage for a process running locally on the machine where Desktop is installed, you can let Auto-Configure create project settings for you (see step 3 below).
You can also set up match rules manually, if you prefer.
The two match type options are Regex and Exe.
The Regex option would be "nunit-agent.exe", or even simply "nunit-agent".
The Exe option tells the NCover profiler to match on the executable name.
You can also use a file path if you want to profile a process only when it runs from a specific location.
Auto-Configure
Another option is to click on the Auto-Configure button and let NCover create match rules for you.
The Processes tab will switch to the Auto-Detection view and start monitoring for .NET processes as soon as you click on Auto-Configure.
Start the test runner, and the executables and assemblies that are being loaded during your testing will display in the detection window.
Switch the Pre-Coverage filter radio button to "Create filter" to review the "Modules to cover" and decide whether to include or exclude modules from the l
Review the list and uncheck any items that shouldn't be covered. For example, you may want to include the nunit-agent.exe., but not the nunit.exe (the GUI).
We also want to create an Exclude rule for the CalcController, since it is simply entering test data, and an Include rule for the CalcTest, which contains the actual unit tests.
Click the checkbox beside each module once to mark with an X to exclude the module. Click twice to mark with a check to include the module.
Note: You can specifically exclude modules by placing an X beside them on this screen, but any modules that are not specifically included will not be profiled, anyway. In other words, not creating an include is functionally the same as creating an exclude rule.
The selections shown above create the filter rules seen below when you click on the Filters tab.
Go the "Processes" tab and click Save to accept these selections, or Re-detect processes to start over.
Collecting Coverage
Note: NCover can only collect coverage on one process at a time.
If you have three Desktop projects that monitor NUnit, only the project you are currently testing should be enabled.
Disable the other two projects using the slider button on the GUI. Then, restart IIS and you should get coverage on the enabled project only.
You can also enable/disable projects from the command line: http://www.ncover.com/support/docs/extras/command-line/ncover-disable-enable
When your project selections are completed, re-start your test runner and run your unit tests.
Go to the Home page and you'll see that the light beside your enabled 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 in the current execution of your project.
When your NUnit tests are complete, close your test runner to stop profiling and allow Desktop to collect coverage data. When the data is aggregated, the results will be automatically displayed below your project on the Project view.
Desktop makes collecting code coverage simple, and then gives you access to dynamic and powerful views of coverage trends.