NCover and Bamboo Integration
We often receive questions about how best to integrate NCover into the build process, and most teams are looking for instructions specific to their build solution. The good news is that NCover 5 makes integration with your CI solution easier than ever and provides even more reporting options.
In this document, we'll focus on Bamboo integration.
Step 1: Create an NCover Project
Your NCover project is where your code coverage results will be sent and displayed in the NCover GUI. Whether you are planning to collect coverage locally with Code Central, or remotely with Collector, you need to create your new project within Code Central and give your project a name.
On a build server, your project will typically be set to collect coverage on NUnit or MSTest, although any .NET testing tool can be used and the process for setting up your project is similar.
Once you have created your NCover project, select "Edit Match Rules" and add a new match rule for the appropriate test runner process (more on this later).
If you're using Code Central to collect coverage locally, you can also use Auto-Configure if you are not sure what process is loading your unit tests. Details about Auto-Configure are available here: http://www.ncover.com/support/docs/code-central/user-guide/coverage-scenarios/covering-build-server.
Also, the following tutorial video outlines the steps for creating a new project and setting process match rules: http://www.ncover.com/resources/videos/ncover-creating-a-new-code-coverage-project.
Save the NCover project and you are ready to build your NCover Run command.
Step 2: The NCover Run Command
Since it's likely that you have more than one project running unit tests on your build server, you can use NCover Run to profile a specific test run. Having a Code Central project set up to simply monitor the NUnit agent, for example, whenever it runs might gather a confusing array of data on unrelated projects.
The NCover Run command allows NCover to:
- Collect data from the covered process.
- Send the coverage results to the NCover project you specify.
- Summarize the coverage results and generate links to the coverage summary html report.
The NCover Run command provides a variety of options that allow you to:
- Specify build Ids.
- Return error codes.
- Output a coverage summary to the console.
- Register the NCover profiler DLLs.
- Define the profiled application's working directory.
The syntax of the Run command will vary depending on your test runner. Specific instructions for NUnit and MSTest are described below.
For NUnit:
- Create a project in Code Central where the coverage results will be sent and displayed.
- On the "Processes" tab of the new project, click "Edit Match Rules"
- Add a match rule of Match type="Regex", Process matching="nunit-agent"
- Save the project (which will be automatically synced to all Collectors), then start building your NCover Run command.
The first part of the NCover Run command is the (required) NCover project, the second half is the profiled application (NUnit).
Use the same syntax in the second part of the Run command that you would use to run NUnit from the command line.
So, a basic NCover Run command will look like this: ncover run --project="MyNUnitProject" -- "nunit-console-x86.exe" "UnitTest.dll"
Try NCover Run from the command line first, which will make it much easier to troubleshoot than running it from the build script.
When NCover runs successfully, coverage will be collected on NUnit and displayed in your project in Code Central.
Once NCover Run is working as expected from the command line, add it to your build script as an
For MSTest:
- Create an NCover project.
- On the "Processes" tab, name your project, then click "Edit Match Rules."
- Add a match rule of Match type="Regex", Process matching="qtagent."
- Save the project (which will be automatically synced to all Collectors), then start building your NCover Run command.
The first part of the NCover Run command is the (required) NCover project and (optional) build ID, the second half is the covered application.
Use the same syntax in the second part of the Run command that you would use to run MSTest from the command line.
So, a basic NCover Run command will look like this: ncover run --project="MyMSTestProject" -- "mstest.exe" "/testcontainer: UnitTest.dll"
Try NCover Run from the command line, which will make it easier to troubleshoot than running it from a build script.
When the Run command completes successfully, coverage will be collected on MSTest and displayed for your project in the NCover GUI.
Once NCover Run is working as expected from the command line, add it to your build script as an
Report Integration
The NCover HTML Coverage Summary Report provides an excellent recap of coverage metrics for a specific execution.
NCover 5 includes the option to include method and class detail in the report, which can be generated from the GUI or the command line: http://www.ncover.com/support/docs/extras/command-line/ncover-report.