# NCover

**NCover Desktop** is a .NET code coverage tool.

This article explains how to link the **Telerik® JustMock** and **NCover** profilers and have passing unit tests with collected code coverage.

## Configuring NCover

> You must install NCover with global profiling **turned off**. Otherwise, you will not be able to integrate it with the TelerikJustMock profiler.\_\_
>
> For more details, follow this link: <https://www.ncover.com/support/docs/extras/command-line/set-install-dir>.

## Linking JustMock and NCover Profilers

To use **NCover** along with the JustMock profiler, you will need to:

1. Configure your NCover project:

   * [MSTest](https://www.ncover.com/support/docs/v4/user-guide/desktop/coverage_scenarios/how_do_i_collect_data_from_mstest) (this points to an article from the NCover web site)
   * [NUnit](https://www.ncover.com/support/docs/v4/user-guide/desktop/coverage_scenarios/how_do_i_collect_data_from_nunit) (this points to an article from the NCover web site)

2. Register the NCover profiler.

   Run an elevated Command Prompt (cmd.exe as administrator). Navigate to the NCover install folder(by default: \*C:\Program Files\NCover v4 Desktop\*) and execute the following line:

   **ncover use --reg**

3. Link the profilers *(depending on the NCover version you are using)* from the JustMock Configuration tool:

   ![NCover Link Profilers](https://www.telerik.com/products/justmock/documentation/assets/bfd96cbf636447dd927588ee72c71fa6/ncoverlinkprofilers.png)

   This process is better described [here](https://www.telerik.com/products/justmock/documentation/integration/code-coverage/codecoverage-tools).

4. Set the **JUSTMOCK_INSTANCE** environment variable to **"1"**.

   Do this by inserting the following line in the previously opened command prompt:

   ```
   SET JUSTMOCK_INSTANCE=1
   ```

5. Then, you will be able to collect the coverage data of your assemblies.

   *For example:*

   ```
   ncover run --project=proj -- "c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe" /testcontainer:"C:\Program Files (x86)\Telerik\JustMock\Examples\CSExamples\JustMock.ElevatedExamples\bin\Debug\JustMock.ElevatedExamples.dll"
   ```

   JustMock elevated tests should pass now:

   ![NCover Test Results](https://www.telerik.com/products/justmock/documentation/assets/97ffa3b27d78b81aa8f29c675eae08d4/ncovertestresults.png)

6. Finally, check if coverage has been collected for your assemblies.

   ![NCover Coverage Results](https://www.telerik.com/products/justmock/documentation/assets/d88c45da7f51e23db96114a55e99affc/ncovercoverageresults.png)

> **Note**
>
> To successfully unlink both profilers, you will need to:
>
> 1. Unlink both profilers, as shown [here](https://www.telerik.com/products/justmock/documentation/integration/code-coverage/codecoverage-tools).
> 2. Unregister the NCover profiler with executing the following line in the command prompt: *ncover use --unreg*

## Visual Studio Integration

Having the profilers linked must be enough for using both JustMock and NCover inside Visual Studio:

![NCoverVSResults](https://www.telerik.com/products/justmock/documentation/assets/e313bf455d63b958dcd6833a85fb4fee/ncovervsresults.png)

## See Also

* [Code Coverage Tools](https://www.telerik.com/products/justmock/documentation/integration/code-coverage/codecoverage-tools)
