Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Typemock NUnit Results to TeamCity

I’ve been using TeamCity for project builds for about 6 months now, but I haven’t used it to it’s full potential as a build server.  I couldn’t get Typemock to run properly on Team City.  I decided to take a look on how to do this.  I thought it would be easy to do using TeamCity.  However, according to the Typemock documentation, we have to use the <exec> command instead of the build in <nunit2> command, which makes this process a lot more involved.

I also wanted to get the NUnit console to return the number of tests that had passed and which tests had failed, as such:


Here’s how I did it.  For this project, I am using the following:

  • TeamCity Professional 4.0.2, build 8222
  • Typemock Isolator 5.2.2 x64
  • NUnit 2.4.6 x64
  • NAnt 0.86 Beta (nightly build from 1/30/2009, 0.86.3317.0)

My TeamCity server is run on x86, so when I run the NAnt script and execute the NUnit tests from the nunit console, I have to make sure to run nunit-console-x86.exe for the tests to run properly.

The project build configuration uses the NAnt build runner.  This file is located in the root directory of my project.  The NAnt executable is included in my tools directory of my project so the build server doesn’t have to have NAnt installed (or even on the client).

So for the NUnit tests to report the test results back to TeamCity, we need to use an addin that comes with TeamCity.  There is some documentation here, but it doesn’t show how to retrieve the addin for NAnt or go into much detail about the exact functionality.

For Typemock to run on the TeamCity machine without having it installed, we have to use the auto-deploy feature (documented here).  Now, what I’ve done was copied the common files and .dlls that I use in my project to a directory (tools/typemock) and then copied the appropriate bit version from either the x86 or x64 directory in the TypeMock/Isolator/5.2 directory.  These 2 files (MockWeaver and ProfileLinker) are specific to x86 or x64, so depending on your TeamCity server, you’ll want to get the correct one.

Here is the target node for the tests in my NAnt script:

<target name="" depends="compile.source">
<if test="${property::exists('teamcity.dotnet.nunitaddin')}">
<echo message="TeamCity NUnit dll's found, copy to NUnit addin directory" />
<mkdir dir="${}" />
<copy todir="${}" flatten="true">
<include name="${teamcity.dotnet.nunitaddin}-2.4.6.*" />

<echo message="Starting to run tests" />
<loadtasks assembly="${typemock.dir}\TypeMock.NAntBuild.dll" />
<typemockregister company="My Company" license="My License" autodeploy="True"/>

<!-- Start Typemock Isolator -->
<!-- Execute tests using NUnit -->
<exec program="${nunit}" failonerror="false" verbose="true">
<arg value="${assemblies.output.dir}MyProject.Core.Tests.dll" />
<arg value="/xml:${tests.output.dir}/MyProject.TestsResults.xml"/>
<!-- Stop Typemock Isolator -->
<typemockstop undeploy="true"/>

Step 1: the <if> statement will determine if the variable, ${teamcity.dotnet.nunitaddin} exists.  This is so we can run our build script locally without having the script fail looking for a variable that isn’t passed when you’re not running TeamCity locally.  If this is a TeamCity build, it will retrieve the correct .dll (JetBrains.TeamCity.NUnitAddin-NUnit-2.4.6.dll in this case) and put it into the addin directory where NUnit is being executed from.

Step 2:  the <loadtasks>, <typemockregister> and <typemockstart> statements will load the necessary .dll for Typemock and NAnt to play nice together.  More about this can be read here. We then have to register typemock and specify the autodeploy property to true.

Step 3:  <exec> – this will run Nunit with the specified test .dll and send the results to a separate folder to view later.  You can run more than a single DLL in the tests by adding another line under the existing Tests.dll <arg value="${assemblies.output.dir}MyProject.Presentation.Tests.dll" /> , but you cannot use the wildcard to specify tests using this method.

Step 4: <typemockstop> will unregister Typemock from the system.

My script runs the tests from a specified directory called AutomatedBuildOutput (as described in Derik Whittaker’s Dimecast), so that is where the variable, ${assemblies.output.dir}, points to.

This should get you pointed in the right direction on getting Typemock tests integrated with TeamCity.

--EDIT--: One more thing, you need to add these 2 Environment Variables to the build configuration for Typemock to run using this method (Step 6: Properties and environment variables

  • COR_PROFILER = {B146457E-9AED-4624-B1E5-968D274416EC}
  • Cor_Enable_Profiling = 0x1


Posted 03-01-2009 2:16 PM by Stephen Wright
Filed under: ,



DotNetShoutout wrote Typemock NUnit Results to TeamCity - Stephen Wright
on 03-01-2009 4:59 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Arjan`s World » LINKBLOG for March 2, 2009 wrote Arjan`s World &raquo; LINKBLOG for March 2, 2009
on 03-02-2009 2:55 PM

Pingback from  Arjan`s World    &raquo; LINKBLOG for March 2, 2009

Mock wrote re: Typemock NUnit Results to TeamCity
on 04-07-2009 10:40 AM

Thanks for the post.

BTW great solution...

Mo -

from Typemock

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)