<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dude, where is my Kaizen? &#187; MSTest</title>
	<atom:link href="http://www.bjoernrochel.de/tag/mstest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bjoernrochel.de</link>
	<description>Björn Rochel&#039;s weblog</description>
	<lastBuildDate>Mon, 21 Jun 2010 07:26:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to: Visual Studio test runner &amp; side by side test code</title>
		<link>http://www.bjoernrochel.de/2009/05/18/how-to-visual-studio-test-runner-side-by-side-test-code/</link>
		<comments>http://www.bjoernrochel.de/2009/05/18/how-to-visual-studio-test-runner-side-by-side-test-code/#comments</comments>
		<pubDate>Mon, 18 May 2009 20:34:49 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[MSTest]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=337</guid>
		<description><![CDATA[After spending a lot of time with xUnit.net I recently had to go back to MSTest for my testing again (because it&#8217;s the de facto standard at my current client which is not negotiable ;-().

Former colleagues of mine will probably laugh about this, because I&#8217;ve had a love-and-hate-relationship with MSTest and especially the VisualStudio runner [...]]]></description>
			<content:encoded><![CDATA[<p>After spending a lot of time with xUnit.net I recently had to go back to MSTest for my testing again (because it&#8217;s the de facto standard at my current client which is not negotiable ;-().
</p>
<p>Former colleagues of mine will probably laugh about this, because I&#8217;ve had a love-and-hate-relationship with MSTest and especially the VisualStudio runner in the past. I won&#8217;t go into details here, but you can read about it <a href="http://www.bjoernrochel.de/tag/mstest/">here</a>. However since I currently have no other option I use what is there. Better writing tests such an environment, than writing no test at all. At least if you ask me.</p>
<p />
This brings me back to the topic of the post. Some prerequisites: I like developing software in a TDD manner and am using Resharper with its &#8216;Generate&#8217; and &#8216;Move To&#8217; features a lot. I like the idea of having test-code side by side with the actual tested code. With this a lot of you&#8217;re daily TDD life becomes at least a bit easier and painless. I see at least two advantages in such an approach:</p>
<ol>
<li>You don&#8217;t have to copy generated classes from the test-assembly to the regular assembly.</li>
<li>You don&#8217;t have to maintain two different folder hierarchies (The one in the code-assembly and the one in the regular assembly) and therefore know exactly where to look for test-code.
</li>
</ol>
<p />
This is one of the things I learned from JP Boodhoo in his NBDN bootcamp,  credit for the general idea goes to him for this. So how can we achieve this in VisualStudio with MSTest? </p>
<p />
DISCLAIMER: The stuff I describe in the rest of the post has to do with modifying the .csproj &#8216;“ msbuild file of a project. If this is a &#8216;no go&#8217; for you, you can probably stop reading here <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . For the rest here is the list of steps I took in order to make it work:</p>
<p>
<strong>Step 1: Add the ProjectType Guids to your project.</strong></p>
<p />
VisualStudio&#8217;s test explorer scans only projects which are of a certain project type (aka the test project) for tests. VS identifies such a project based on the value of a particular node in the .csproj file, the <em>ProjectTypeGuid</em> node. Simply copy this one from an actual test project to the .csproj of your regular assembly. Another option of course would be to start with a test project from scratch. </p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;Project ToolsVersion=&quot;3.5&quot; DefaultTargets=&quot;Build&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;Configuration Condition=&quot; &#039;$(Configuration)&#039; == &#039;&#039; &quot;&gt;Debug&lt;/Configuration&gt;
    &lt;Platform Condition=&quot; &#039;$(Platform)&#039; == &#039;&#039; &quot;&gt;AnyCPU&lt;/Platform&gt;
    &lt;ProductVersion&gt;9.0.30729&lt;/ProductVersion&gt;
    &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
    &lt;!-- The line below has to be added to regular projects --&gt;
    &lt;ProjectTypeGuids&gt;{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}&lt;/ProjectTypeGuids&gt;
    &lt;ProjectGuid&gt;{890DA3CA-999A-474E-BA87-05A834CAB7B8}&lt;/ProjectGuid&gt;
    &lt;OutputType&gt;Library&lt;/OutputType&gt;
    &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
    &lt;RootNamespace&gt;SpecReport&lt;/RootNamespace&gt;
    &lt;AssemblyName&gt;SpecReport&lt;/AssemblyName&gt;
    &lt;TargetFrameworkVersion&gt;v3.5&lt;/TargetFrameworkVersion&gt;
    &lt;FileAlignment&gt;512&lt;/FileAlignment&gt;
  &lt;/PropertyGroup&gt;
</pre>
<p><strong>Step 2: Apply conditional compilation for not including the test code when compiling in release mode</strong></p>
<p />
So, the tests sit right next to the tested code, right? We presumable don&#8217;t want our tests to be deployed to production. We can achieve this in MSBuild fairly easy with conditional compilation and wildcards. </p>
<pre class="brush: xml">
  &lt;ItemGroup&gt;
    &lt;!-- The line below skips all files ending with &#039;Spec.cs&#039; when compiling in a mode other than DEBUG --&gt;
    &lt;Compile Condition=&quot;&#039;$(Configuration)&#039; == &#039;Debug&#039;&quot; Include=&quot;**\*Specs.cs&quot; /&gt;
    &lt;Compile Include=&quot;IReportEngine.cs&quot; /&gt;
    &lt;Compile Include=&quot;IReportGenerator.cs&quot; /&gt;
    &lt;Compile Include=&quot;Notification.cs&quot; /&gt;
    &lt;Compile Include=&quot;NotificationCollection.cs&quot; /&gt;
    &lt;Compile Include=&quot;Properties\AssemblyInfo.cs&quot; /&gt;
    &lt;Compile Include=&quot;ReportEngine.cs&quot; /&gt;
    &lt;Compile Include=&quot;ReportEngineArgs.cs&quot; /&gt;
  &lt;/ItemGroup&gt;
</pre>
<p><strong>Step 3: Apply conditional compilation for not deploying the test-related assemblies when compiling in release mode<br />
</strong></p>
<p />
In order to get rid of the test-specific assemblies for production deployment you can also apply conditionals to the assembly references of a project.</p>
<pre class="brush: xml">
&lt;ItemGroup&gt;
&lt;Reference Condition=&quot;&#039;$(Configuration)&#039; == &#039;Debug&#039;&quot; Include=&quot;Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL&quot; /&gt;
    &lt;Reference Condition=&quot;&#039;$(Configuration)&#039; == &#039;Debug&#039;&quot; Include=&quot;Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL&quot;&gt;
      &lt;SpecificVersion&gt;False&lt;/SpecificVersion&gt;
      &lt;HintPath&gt;..\Externals\RhinoMocks35\Rhino.Mocks.dll&lt;/HintPath&gt;
    &lt;/Reference&gt;
    &lt;Reference Include=&quot;System&quot; /&gt;
    &lt;Reference Include=&quot;System.Core&quot;&gt;
      &lt;RequiredTargetFramework&gt;3.5&lt;/RequiredTargetFramework&gt;
    &lt;/Reference&gt;
    &lt;Reference Include=&quot;System.Xml.Linq&quot;&gt;
      &lt;RequiredTargetFramework&gt;3.5&lt;/RequiredTargetFramework&gt;
    &lt;/Reference&gt;
    &lt;Reference Include=&quot;System.Data.DataSetExtensions&quot;&gt;
      &lt;RequiredTargetFramework&gt;3.5&lt;/RequiredTargetFramework&gt;
    &lt;/Reference&gt;
    &lt;Reference Include=&quot;System.Data&quot; /&gt;
    &lt;Reference Include=&quot;System.Xml&quot; /&gt;
  &lt;/ItemGroup&gt;
</pre>
<p>
Et voila: The approach described in this post seams to work fine. At least I&#8217;m not experiencing side effects since I&#8217;ve configured it that way &#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/05/18/how-to-visual-studio-test-runner-side-by-side-test-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some words regarding MSTest</title>
		<link>http://www.bjoernrochel.de/2008/08/19/some-words-regarding-mstest/</link>
		<comments>http://www.bjoernrochel.de/2008/08/19/some-words-regarding-mstest/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 19:41:50 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[MSTest]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://bjro.de/2008/08/19/some-words-regarding-mstest/</guid>
		<description><![CDATA[Today I stumbled again about this and feel (once more) a bit frustrated about the current version of MSTest.
In theory Visual Studio VS2008 supports Test-Class-Inheritance. Once you actually start using it, you pretty fast encounter one big limitation:
The test base class must be in the same assembly as the derived test
Mh,Â  is that such an [...]]]></description>
			<content:encoded><![CDATA[<p>Today I stumbled again about this and feel (once more) a bit frustrated about the current version of <strong>MSTest</strong>.</p>
<p>In theory Visual Studio VS2008 supports Test-Class-Inheritance. Once you actually start using it, you pretty fast encounter one big limitation:</p>
<p><strong>The test base class must be in the same assembly as the derived test</strong></p>
<p>Mh,Â  is that such an uncommon scenario that it&#8217;s not supported? Personally I don&#8217;t think so. What about BDD extensions for MSTest? Do I need to have a Specification-base class in each test assembly? Oh, c&#8217;mon ?!</p>
<p>Just when you think it can&#8217;t get worse, you realize that</p>
<p><strong>Tests using Test-Class-Inheritance are NOT EXECUTED when running inside a VS TFS 2008 TeamBuild</strong></p>
<p>Awesome <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>Besides that we also still have the *.vsmdi-hell (Replace * with the name your Solution and a number between 1 and 100 . . .), but that a different story.</p>
<p>If it was my personal decision I would ditch MSTest right away. It&#8217;ll be interesting to see whether I&#8217;m able to convince our development leads to go down that road . . .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2008/08/19/some-words-regarding-mstest/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
