Running TypeMock with Gallio on build server or agent without local install

I tend to dislike having to do local installs of software on my Puzzlepart build servers (or agents) because this also means that developers will need to install something specific to be able to build the project. That's bad and unfortunately the norm for the projects I've downloaded and reviewed lately.

To avoid this I've got all my common build dependencies in a shared repository in svn, and I use svn externals to add this to the root of my project trunks. This enables me to, over time, create tags on my buildtools repository and have older projects reference older build tools as I upgrade my stack.

My scenario was to use the Gallio msbuild task to run my tests and also use the integrated TypeMock testrunner in this context because I need to do a lot of Sharepoint unit testing. First problem was that Gallio uses the 4.0 version of the runner. This was fixed by adding the regkey as described in my gallio-dev forum post. Second problem was that TypeMock.Integration.dll (which Gallio uses) depends on registry to locate the installdir for typemock. I want to be able to run this without having to run the TypeMock MSI so some registry keys needs to be manipulated.

First I added most of the TypeMock 5.1 binaries to my buildtools svn repository (no, didn't bother to investigate which files I actually HAD to include - TypeMock Team: It would be nice to have this documented in order to create the smallest possible footprint for this scenario).

Then I updated my build script to manipulate registry on the build machine. Yes, this is kinda bad and it requires running under local administrative rights, but it works. I also might note that I passed a feature request on to the TypeMock team to make the Typemock.Integration.dll look for a config file in the same dir as the Typemock.Integration.dll file to resolve TypeMock installdir, company and licensekey.

There is some added complexity here to support the current Gallio distribution. In the future ignore that and just rely on the 5.0 regkey stuff as soon as gallio ships with the 5.0 version of the typemock.integration.dll. Here is the sample MsBuild task that does all the registry baddness using the RegistryRead and RegistryWrite tasks from the MsBuildTasks project on tigris:

  <Target Name="Tests" DependsOnTargets="Compile">
<!--
Typemock reads registry only to locate binaries.
We need to temporarily point this to the typemock binaries included with the build distributon
-->
<PropertyGroup>
<TypeMockInstallDir></TypeMockInstallDir>
<TypeMockBuildDistributionDir>$(MSBuildProjectDirectory)\buildtools\TypeMock</TypeMockBuildDistributionDir>
<TypeMock40RegKey>HKEY_LOCAL_MACHINE\SOFTWARE\TypeMock\TypeMock.NET</TypeMock40RegKey>
<TypeMock50RegKey>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TypeMock\TypeMock.NET</TypeMock50RegKey>
<!-- This must be used for the current Gallio MsBuild task. Change to 5.0 when gallio updates typemock.integration.dll -->
<TypeMockRegKey>$(TypeMock40RegKey)</TypeMockRegKey>
<TypeMockLicense>G09F-APBQ-2AF9-2N2D-D7C1</TypeMockLicense>
<TypeMockLicenseCompany>PUZZLEPART</TypeMockLicenseCompany>
</PropertyGroup>

<RegistryRead
KeyName="$(TypeMockRegKey)"
ValueName="InstallDir">
<Output TaskParameter="Value" PropertyName="TypeMockInstallDir" />
</RegistryRead>
<RegistryWrite
KeyName="$(TypeMockRegKey)"
ValueName="InstallDir"
Value="$(TypeMockBuildDistributionDir)" />

<!-- Repeat this process for License and Company registry keys if required -->

<Message Text="Executing Gallio task with TypeMock runner using TypeMock at $(TypeMockBuildDistributionDir)" />

<Gallio IgnoreFailures="true" Assemblies="@(TestAssemblies)" ReportTypes="xml" RunnerType="TypeMock" >
<!-- This tells MSBuild to store the output value of the task's ExitCode property into the project's ExitCode property -->
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
</Gallio>

<RegistryWrite
KeyName="$(TypeMockRegKey)"
ValueName="InstallDir"
Value="$(TypeMockInstallDir)" />

<Message Text="Reinstated TypeMock registry key to value $(TypeMockInstallDir)" />

<Error Text="Tests execution failed" Condition="'$(ExitCode)' != 0" />
</Target>

UPDATE: Just a minor note to self (as it was hard to find documentation): In order to run just one category of tests with the Gallio MsBuild Task use a Filter attribute like this: <Gallio ... Filter="CategoryName: unittests" >

3 Comments

Comments have been disabled for this content.