NCover 4 and TeamCity TestRunner Integration

A few weeks ago, I posted about build server integration with NCover 4, and said that the dev team was working to improve TeamCity coverage, so here’s the good news about NUnit integration!

You can still run nunit-console from your build script if you prefer, but making some simple changes to the the TeamCity TestRunner config will allow NCover 4 to profile the integrated NUnit runner without changing your test process.

In the TeamCity project where you want NC4 to profile NUnit, go to Configuration Step 6: Build Parameters:

Adding Build Parameters.

Set the System Property as appropriate for your build. If you’re using the TeamCity test runner, you have probably already configured that setting to look something like the following:

NUnit System Property

For NCover to detect the NUnit tests when they are executed by the build task, the build agent environment needs to be configured to enable NCover profiling.

This is easily done by adding two profiling environment variables:

NCover Environment Variables

These changes will enable NCover 4 to detect the TeamCity process that runs your unit tests. Depending on your test configuration, that exe will be some variation of  “JetBrains.TeamCity.PlatformProcessRunner.v4.0.msil.exe”. If your tests are designedfor the v2 CLR, you’ll need to watch for the v2 exe.

Once you’ve modified the environment variables for the build as described above, you can create an NCover 4 project to collect your unit test coverage.

Simply add a new project and press the Auto-configure button. NCover is now waiting for you to start the application you want to profile. Leave NCover in Auto-config mode, go back to TeamCity and start the NUnit task.

While that task runs, go back to NCover and you will see the processes that are started during the NUnit testing displayed in the detection window. Once the modules you want to cover are listed, select the ones you want to keep and then save the NCover project.

You don’t have to wait for all of your NUnit tests to complete, unless it’s necessary to make sure that all the modules you want to profile are loaded.

Once you save the NCover project settings, re-start the TeamCity NUnit task to collect your first coverage run.

After you set the TeamCity build parameters and configure your NCover project, covering TeamCity’s NUnit tests should be seamless and automatic.

Comments

  1. Chris Carpenter says:

    I am trying to do a similar setup to this, but with MSTest instead of NUnit. What would I use in place of the system.teamcity.dotnet.nunitlauncher property to indicate the unit test executable?

  2. Chris, if you’re already running MsTest in TeamCity I suspect you will see processes created for “qtagent32.exe”. Since TeamCity does not have live results reporting for MsTest like it does for NUnit I don’t know that there will be a parent process to watch for in this case. Check out the TC docs and see if you agree:

    http://confluence.jetbrains.net/display/TCD7/MSTest+Support