NCover Documentation

NCover monitors programs for coverage rather than making the user launch their program using NCover to get coverage. For simple testing, the difference is probably not very noticeable, but for software running on test or build clusters, NCover makes it much easier to gather coverage.

In this coverage model, you specify which programs you'd like to profile, and NCover does all the work of making sure that happens. Even so, there are users who want to be more precise about the way they collect coverage data. They would like to open a command prompt session and have coverage collected on specific programs within that session. Or they want to do the same thing for a build server, where multiple builds are happening concurrently.

The first step is to disable the global NCover profiler. This can be accomplished simply by removing four global environment variables from the computer in question.

After NCover has been installed, you will find the following global environment variables defined on the machine.

CORECLR_ENABLE_PROFILING=1
CORECLR_PROFILER=NCover.ProfilerLauncher
COR_ENABLE_PROFILING=1
COR_PROFILER=NCover.ProfilerLauncher

To disable the global profiler, simply remove those entries from the global environment. This can be done from the System Properties dialog by clicking the "Environment Variables" button and removing the entries from the System Variables section of the dialog.

Please note, once you disable the global profiler settings, NCover will only operate in the manner described in the rest of this article. You will not be able to simply set match rules and have coverage collected. To restore global coverage monitoring, just restore the global environment variables to their original settings.

Now, to collect coverage locally with NCover, you can use the "NCover Run" command. To run coverage on the NUnit test runner, for example, you could use a command line that looks something like this.

ncover run --project='MyProject' -- nunit-console.exe mytest.dll

The NCover Run command will set up the environment locally within the command prompt so that the processes launched by NCover Run will be monitored for coverage. The NCover Run command does require a project to be created, as well.

So, in this example, you must have 'MyProject' set up in NCover Desktop or Code Central with the appropriate match rules to gather coverage on nunit-console when it launches. (More on the NCover Run command here.)

Let's say you have a build server configured to collect coverage data with NCover. Maybe you are building ten different applications with accompanying unit tests, etc. Using NCover Run in your build script to run your tests will allow you to have tighter control over which test processes are selected for coverage and which projects will be used to store the resulting data.

Note: These command updates are present in NCover version 4.1.2099.921 and beyond. Please make sure you upgrade your version of NCover before trying it out.

If you still need technical assistance, we can help:

Submit A Support Ticket