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="tests.run.MyProject" depends="compile.source">
<if test="${property::exists('teamcity.dotnet.nunitaddin')}">
<echo message="TeamCity NUnit dll's found, copy to NUnit addin directory" />
<mkdir dir="${nunit.addins.directory}" />
<copy todir="${nunit.addins.directory}" flatten="true">
<fileset>
<include name="${teamcity.dotnet.nunitaddin}-2.4.6.*" />
</fileset>
</copy>
</if>
<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 -->
<typemockstart/>
<!-- 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"/>
</exec>
<!-- Stop Typemock Isolator -->
<typemockstop undeploy="true"/>
</target>
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