<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Stephen Wright : Typemock</title><link>http://devlicio.us/blogs/steve_wright/archive/tags/Typemock/default.aspx</link><description>Tags: Typemock</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Typemock NUnit Results to TeamCity</title><link>http://devlicio.us/blogs/steve_wright/archive/2009/03/01/typemock-nunit-results-to-teamcity.aspx</link><pubDate>Sun, 01 Mar 2009 20:16:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:44742</guid><dc:creator>Stephen Wright</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/steve_wright/rsscomments.aspx?PostID=44742</wfw:commentRss><comments>http://devlicio.us/blogs/steve_wright/archive/2009/03/01/typemock-nunit-results-to-teamcity.aspx#comments</comments><description>&lt;p&gt;I’ve been using &lt;a href="http://www.jetbrains.com/teamcity"&gt;TeamCity&lt;/a&gt; for project builds for about 6 months now, but I haven’t used it to it’s full potential as a build server.&amp;nbsp; I couldn’t get &lt;a href="http://www.typemock.com/"&gt;Typemock&lt;/a&gt; to run properly on Team City.&amp;nbsp; I decided to take a look on how to do this.&amp;nbsp; I thought it would be easy to do using TeamCity.&amp;nbsp; However, according to the Typemock documentation, we have to use the &amp;lt;exec&amp;gt; command instead of the build in &amp;lt;nunit2&amp;gt; command, which makes this process a lot more involved.&lt;/p&gt;  &lt;p&gt;I also wanted to get the NUnit console to return the number of tests that had passed and which tests had failed, as such:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://devlicio.us/blogs/steve_wright/20090301_1347_265EF52A.png" title="2009-03-01_1347" style="border-width:0px;display:inline;" alt="2009-03-01_1347" width="579" border="0" height="55" /&gt; &lt;/p&gt;  &lt;p&gt;Here’s how I did it.&amp;nbsp; For this project, I am using the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;TeamCity Professional 4.0.2, build 8222 &lt;/li&gt;    &lt;li&gt;Typemock Isolator 5.2.2 x64 &lt;/li&gt;    &lt;li&gt;NUnit 2.4.6 x64 &lt;/li&gt;    &lt;li&gt;NAnt 0.86 Beta (nightly build from 1/30/2009, 0.86.3317.0) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;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. &lt;/p&gt;  &lt;p&gt;The project build configuration uses the NAnt build runner.&amp;nbsp; This file is located in the root directory of my project.&amp;nbsp; 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).&lt;/p&gt;  &lt;p&gt;So for the NUnit tests to report the test results back to TeamCity, we need to use an addin that comes with TeamCity.&amp;nbsp; There is some documentation &lt;a href="http://www.jetbrains.net/confluence/display/TCD4/TeamCity+Addin+for+NUnit"&gt;here&lt;/a&gt;, but it doesn’t show how to retrieve the addin for NAnt or go into much detail about the exact functionality.&lt;/p&gt;  &lt;p&gt;For Typemock to run on the TeamCity machine without having it installed, we have to use the auto-deploy feature (documented &lt;a href="http://www.typemock.com/Docs/UserGuide/newGuide/Documentation/InstallingAutoDeploy.html"&gt;here&lt;/a&gt;).&amp;nbsp; 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.&amp;nbsp; 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.&lt;/p&gt;  &lt;p&gt;Here is the target node for the tests in my NAnt script:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;target&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;tests.run.MyProject&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;depends&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;compile.source&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;if&lt;/span&gt; &lt;span class="attr"&gt;test&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${property::exists(&amp;#39;teamcity.dotnet.nunitaddin&amp;#39;)}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;echo&lt;/span&gt; &lt;span class="attr"&gt;message&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TeamCity NUnit dll&amp;#39;s found, copy to NUnit addin directory&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;mkdir&lt;/span&gt; &lt;span class="attr"&gt;dir&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${nunit.addins.directory}&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;copy&lt;/span&gt; &lt;span class="attr"&gt;todir&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${nunit.addins.directory}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;flatten&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;fileset&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;include&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${teamcity.dotnet.nunitaddin}-2.4.6.*&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;                    &lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;fileset&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;copy&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;            &lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;if&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;echo&lt;/span&gt; &lt;span class="attr"&gt;message&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Starting to run tests&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;        &lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;loadtasks&lt;/span&gt; &lt;span class="attr"&gt;assembly&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${typemock.dir}\TypeMock.NAntBuild.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;typemockregister&lt;/span&gt; &lt;span class="attr"&gt;company&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;My Company&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;license&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;My License&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;autodeploy&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class="rem"&gt;&amp;lt;!-- Start Typemock Isolator --&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;typemockstart&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;&amp;lt;!-- Execute tests using NUnit --&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;exec&lt;/span&gt; &lt;span class="attr"&gt;program&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${nunit}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;failonerror&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;verbose&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;arg&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${assemblies.output.dir}MyProject.Core.Tests.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;arg&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/xml:${tests.output.dir}/MyProject.TestsResults.xml&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;            &lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;exec&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;&amp;lt;!-- Stop Typemock Isolator --&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;typemockstop&lt;/span&gt; &lt;span class="attr"&gt;undeploy&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;b&gt;Step 1&lt;/b&gt;: the &amp;lt;if&amp;gt; statement will determine if the variable, ${teamcity.dotnet.nunitaddin} exists.&amp;nbsp; 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.&amp;nbsp; 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.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 2&lt;/b&gt;:&amp;nbsp; the &amp;lt;loadtasks&amp;gt;, &amp;lt;typemockregister&amp;gt; and &amp;lt;typemockstart&amp;gt; statements will load the necessary .dll for Typemock and NAnt to play nice together.&amp;nbsp; More about this can be read &lt;a href="http://www.typemock.com/Docs/UserGuide/NAntBuild.html"&gt;here&lt;/a&gt;. We then have to register typemock and specify the autodeploy property to true.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 3&lt;/b&gt;:&amp;nbsp; &amp;lt;exec&amp;gt; – this will run Nunit with the specified test .dll and send the results to a separate folder to view later.&amp;nbsp; You can run more than a single DLL in the tests by adding another line under the existing Tests.dll &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;arg&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;${assemblies.output.dir}MyProject.Presentation.Tests.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; , but you cannot use the wildcard to specify tests using this method.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 4&lt;/b&gt;: &amp;lt;typemockstop&amp;gt; will unregister Typemock from the system.&lt;/p&gt;

&lt;p&gt;My script runs the tests from a specified directory called AutomatedBuildOutput (as described in &lt;a href="http://devlicio.us/blogs/derik_whittaker/default.aspx"&gt;Derik Whittaker’s&lt;/a&gt; &lt;a href="http://dimecasts.net/Casts/CastDetails/81"&gt;Dimecast&lt;/a&gt;), so that is where the variable, ${assemblies.output.dir}, points to.&lt;/p&gt;

&lt;p&gt;This should get you pointed in the right direction on getting Typemock tests integrated with TeamCity.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;--EDIT--&lt;/b&gt;: One more thing, you need to add these 2 &lt;b&gt;Environment Variables&lt;/b&gt; to the build configuration for Typemock to run using this method (Step 6: Properties and environment variables&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;COR_PROFILER = {B146457E-9AED-4624-B1E5-968D274416EC} &lt;/li&gt;

  &lt;li&gt;Cor_Enable_Profiling = 0x1 &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src="http://devlicio.us/blogs/steve_wright/Typemock_env_2F75D356.png" title="Typemock_env" style="border-width:0px;display:inline;" alt="Typemock_env" width="621" border="0" height="248" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=44742" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/steve_wright/archive/tags/Typemock/default.aspx">Typemock</category><category domain="http://devlicio.us/blogs/steve_wright/archive/tags/TeamCity/default.aspx">TeamCity</category></item></channel></rss>