<?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>out &#62;&#62; m_Conscientia; &#187; TDD</title>
	<atom:link href="http://blog.hypercomplex.co.uk/index.php/tag/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hypercomplex.co.uk</link>
	<description>a multidimensional braindump</description>
	<lastBuildDate>Mon, 02 Aug 2010 22:30:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>When dependency injection meets IDisposable</title>
		<link>http://blog.hypercomplex.co.uk/index.php/2009/06/when-dependency-injection-meets-idisposable/</link>
		<comments>http://blog.hypercomplex.co.uk/index.php/2009/06/when-dependency-injection-meets-idisposable/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 21:50:58 +0000</pubDate>
		<dc:creator>Alex Peck</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[IDisposable]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.hypercomplex.co.uk/?p=500</guid>
		<description><![CDATA[What follows is a solution which should really have been obvious to me the first time I faced the problem: how do you decouple logic and instantiation of collaborating objects when faced with an IDisposable class? Consider this: public class NiceClass &#123; private DependentClass injectedDependency; &#160; public NiceClass&#40;DependentClass injectedDependency&#41; &#123; this.injectedDependency = injectedDependency; &#125; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>What follows is a solution which should really have been obvious to me the first time I faced the problem: how do you decouple logic and instantiation of collaborating objects when faced with an IDisposable class? Consider this:</p>

<div class="wp_codebox"><table><tr id="p5004"><td class="code" id="p500code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> NiceClass
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> DependentClass injectedDependency<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> NiceClass<span style="color: #008000;">&#40;</span>DependentClass injectedDependency<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">injectedDependency</span> <span style="color: #008000;">=</span> injectedDependency<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> CoupledMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>IFace c <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Face<span style="color: #008000;">&#40;</span>injectedDependency<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// do something with c</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>We can see that injectedDependency is not coupled, but what about the local instance of Face in CoupledMethod? To decouple it use a delegate to return the IFace instance instead of calling new directly. If the coupling had been to a concrete type (Face), we could refactor to an abstract type (IFace) or wrapper first.</p>

<div class="wp_codebox"><table><tr id="p5005"><td class="code" id="p500code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> NiceClass
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> IFace IFaceCreatorDelegate<span style="color: #008000;">&#40;</span>DependentClass injectedDependency<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> DependentClass injectedDependency<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> IFaceCreatorDelegate iFaceCreator<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> NiceClass<span style="color: #008000;">&#40;</span>DependentClass injectedDependency, IFaceCreatorDelegate iFaceCreator<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">injectedDependency</span> <span style="color: #008000;">=</span> injectedDependency<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">iFaceCreator</span> <span style="color: #008000;">=</span> iFaceCreator<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> CoupledMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>IFace c <span style="color: #008000;">=</span> iFaceCreator<span style="color: #008000;">&#40;</span>injectedDependency<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// do something with c</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>This is an additional three lines of code, which arguably makes the control flow harder to read statically. It does, however, improve testability. I think of this as equivalent to the classic tradeoff between <a href="http://www.threeriversinstitute.org/AbstractVsConcreteParameters.html">abstract and concrete parameters</a>.</p>
<p>Instantiating NiceClass is not too arduous either with a lambda expression (although it is still a little verbose).</p>

<div class="wp_codebox"><table><tr id="p5006"><td class="code" id="p500code6"><pre class="csharp" style="font-family:monospace;">NiceClass nice <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> NiceClass<span style="color: #008000;">&#40;</span>
   dependency, 
   <span style="color: #008000;">&#40;</span>DependentClass d<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Face<span style="color: #008000;">&#40;</span>d<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hypercomplex.co.uk/index.php/2009/06/when-dependency-injection-meets-idisposable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependency Injection &amp; Testability</title>
		<link>http://blog.hypercomplex.co.uk/index.php/2009/06/dependency-injection-testability/</link>
		<comments>http://blog.hypercomplex.co.uk/index.php/2009/06/dependency-injection-testability/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 19:01:06 +0000</pubDate>
		<dc:creator>Alex Peck</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[code coverage]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.hypercomplex.co.uk/?p=111</guid>
		<description><![CDATA[When objects have no (or few) collaborators it&#8217;s relatively easy to get high unit test code coverage. As the number and complexity of collaborators increases, so too does the difficulty in obtaining decent coverage. This talk illustrates why dependency injection principles improve the testability of your code, and ease mock/stub based unit testing.]]></description>
			<content:encoded><![CDATA[<p>When objects have no (or few) collaborators it&#8217;s relatively easy to get high unit test code coverage. As the number and complexity of collaborators increases, so too does the difficulty in obtaining decent coverage. This talk illustrates why dependency injection principles improve the testability of your code, and ease <a href="http://martinfowler.com/articles/mocksArentStubs.html" target="_blank">mock/stub based unit testing</a>.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/RlfLCWKxHJ0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/RlfLCWKxHJ0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hypercomplex.co.uk/index.php/2009/06/dependency-injection-testability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BDD: Behaviour Driven Development</title>
		<link>http://blog.hypercomplex.co.uk/index.php/2009/05/behaviour-driven-development/</link>
		<comments>http://blog.hypercomplex.co.uk/index.php/2009/05/behaviour-driven-development/#comments</comments>
		<pubDate>Sat, 16 May 2009 23:03:16 +0000</pubDate>
		<dc:creator>Alex Peck</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.hypercomplex.co.uk/?p=541</guid>
		<description><![CDATA[Since this talk was three years ago it is now clear BDD didn&#8217;t set the world on fire. That said, I like the focus here on the mindset of the developer. My interpretation of BDD is that the terminology you use affects your development process. It&#8217;s not fundamentally different to TDD, rather there is a [...]]]></description>
			<content:encoded><![CDATA[<p><embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=8135690990081075324&#038;hl=en&#038;fs=true style=width:400px;height:326px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed></p>
<p>Since this talk was three years ago it is now clear BDD didn&#8217;t set the world on fire. That said, I like the focus here on the mindset of the developer. My interpretation of BDD is that the terminology you use affects your development process. It&#8217;s not fundamentally different to TDD, rather there is a change in terminology which subtely influences your design process.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hypercomplex.co.uk/index.php/2009/05/behaviour-driven-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TDD: An empirical study at Microsoft</title>
		<link>http://blog.hypercomplex.co.uk/index.php/2009/01/tdd-an-empirical-study-at-microsoft/</link>
		<comments>http://blog.hypercomplex.co.uk/index.php/2009/01/tdd-an-empirical-study-at-microsoft/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 23:49:01 +0000</pubDate>
		<dc:creator>Alex Peck</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.hypercomplex.co.uk/?p=520</guid>
		<description><![CDATA[In my experience, TDD focuses you on writing testable code with good edge case and error handling. Most TDD discussions revolve around this kind of anecdotal evidence of improvement. Microsoft research have published a paper exploring the effect of TDD on various quality metrics. You can check out a short Channel 9 overview here.]]></description>
			<content:encoded><![CDATA[<p>In my experience, <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> focuses you on writing testable code with good edge case and error handling. Most TDD discussions revolve around this kind of anecdotal evidence of improvement.</p>
<p>Microsoft research have published a <a href="http://research.microsoft.com/en-us/projects/esm/nagappan_tdd.pdf">paper</a> exploring the effect of TDD on various quality metrics. You can check out a short Channel 9 overview <a href="http://channel9.msdn.com/posts/Peli/Experimental-study-about-Test-Driven-Development/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hypercomplex.co.uk/index.php/2009/01/tdd-an-empirical-study-at-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
