<?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/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Headspring &#187; Mahendra Mavani</title>
	<atom:link href="http://www.headspring.com/author/mmavani/feed" rel="self" type="application/rss+xml" />
	<link>http://www.headspring.com</link>
	<description>Custom software... Done right the first time.</description>
	<lastBuildDate>Wed, 16 May 2012 18:27:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<copyright>Copyright © Headspring 2012 </copyright>
	<managingEditor>marketing@headspring.com (Jeffrey Palermo and Kevin Hurwitz)</managingEditor>
	<webMaster>marketing@headspring.com (Jeffrey Palermo and Kevin Hurwitz)</webMaster>
	<ttl>1440</ttl>
	<image>
		<url>http://www.headspring.com/wp-content/uploads/2012/05/HeadspringFlair144.jpg</url>
		<title>Headspring</title>
		<link>http://www.headspring.com</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle>We believe there is a better way</itunes:subtitle>
	<itunes:summary>Are you a lifelong learner?  Are you always searching for better ways to develop and maintain software?  So are we!  A passion for learning and growth is a core value at Headspring.  In this podcast, Headspring consultants, programmers, software developers, managers, and executives share the skills, techniques, patterns, and tools that have proven effective on clients&#039; consulting projects.  Headspring is a software consulting company in Austin, TX and has been recognized on the Inc 500 list and the Austin Business Journal&#039;s Best Place to Work award.</itunes:summary>
	<itunes:keywords>headspring, software, line, business, enterprise, applications, custom, MVC, Net, C, database, SQL</itunes:keywords>
	<itunes:category text="Technology" />
	<itunes:category text="Business" />
	<itunes:category text="Education">
		<itunes:category text="Training" />
	</itunes:category>
	<itunes:author>Jeffrey Palermo and Kevin Hurwitz</itunes:author>
	<itunes:owner>
		<itunes:name>Jeffrey Palermo and Kevin Hurwitz</itunes:name>
		<itunes:email>marketing@headspring.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.headspring.com/wp-content/uploads/2012/05/HeadspringFlair600.jpg" />
		<item>
		<title>TDD Caveat &#124; How not to follow Test Driven Development</title>
		<link>http://www.headspring.com/2011/07/tdd-caveat-how-not-to-follow-test-driven-development</link>
		<comments>http://www.headspring.com/2011/07/tdd-caveat-how-not-to-follow-test-driven-development#comments</comments>
		<pubDate>Fri, 29 Jul 2011 18:56:11 +0000</pubDate>
		<dc:creator>Mahendra Mavani</dc:creator>
				<category><![CDATA[Developer Deep Dive]]></category>

		<guid isPermaLink="false">http://www.headspring.com/?p=1030</guid>
		<description><![CDATA[TDD or Test Driven Development was considered an industry buzz for a ...]]></description>
			<content:encoded><![CDATA[<p align="justify">TDD or <a href="http://www.agiledata.org/essays/tdd.html" target="_blank">Test Driven Development</a> was considered an industry buzz for a while. Now a days it is considered more of a main stream development methodology. we, at <a href="http://headspring.com" target="_blank">Headspring</a>, are among those early adopters who likes to walk on cutting edge technologies.</p>
<p align="justify">Over last 5 year, I have transition through different stages of mind set when it comes to unit testing or TDD in general. As an early adoptor I was curious to know to what extend we can take this concept. At this stage, my unit test looked more state testing i.e</p>
<div class="csharpcode">
<pre>[Test]</pre>
</div>
<div class="csharpcode">
<pre><span class="kwrd">public</span> <span class="kwrd">void</span> Should_Add_Two_Number()</pre>
</div>
<div class="csharpcode">
<pre>{</pre>
</div>
<div class="csharpcode">
<pre>    var number1 = 100;</pre>
</div>
<div class="csharpcode">
<pre>    var number2 = 50;</pre>
</div>
<div class="csharpcode">
<pre>    var sum = number1 + number2;</pre>
</div>
<div class="csharpcode">
<pre>    sum.ShouldEqual(150);</pre>
</div>
<div class="csharpcode">
<pre>}</pre>
</div>
<p>As I moved further and realize power of maintainability and loosely coupled design,<span id="more-1030"></span> I started designing solution in terms of interfaces. With that my knowledge on TDD expanded towards interaction testing. Mocking frameworks like <a href="http://ayende.com/wiki/Rhino+Mocks.ashx" target="_blank">Rhino.Mock</a> and Moq, TypeMock etc emerged during that timeframe to support such testing scenarios. And those test now started looking like this:<!--more--></p>
<div class="csharpcode">
<pre>[Test]</pre>
</div>
<div class="csharpcode">
<pre><span class="kwrd">public</span> <span class="kwrd">void</span> Use_Is_Anything_when_args_are_not_important()</pre>
</div>
<div class="csharpcode">
<pre>{</pre>
</div>
<div class="csharpcode">
<pre>    <span class="kwrd">const</span> <span class="kwrd">int</span> intToReturn = 5;</pre>
</div>
<div class="csharpcode">
<pre>    _stub = MockRepository.GenerateStub&lt;ISampleInterface&gt;();</pre>
</div>
<div class="csharpcode">
<pre>    _stub.Stub(s =&gt; s.MethodThatReturnsInteger(<span class="str">"foo"</span>)).Return(intToReturn);</pre>
</div>
<div class="csharpcode">
<pre>    _stub.MethodThatReturnsInteger(<span class="str">"foo"</span>).ShouldEqual(intToReturn);</pre>
</div>
<div class="csharpcode">
<pre>}</pre>
</div>
<p>Exploring further, I started utilizing more features provided by those mocking framework. Now you have way to not only  ensure method on stub/mock returns predictable value, but also make assertion that it was called with right argument. Taking this even further, when you have more services to interact with, these frameworks have option to assert sequence in which you call them. Example of first case may look like this:</p>
<div class="csharpcode">
<pre>[Test]</pre>
</div>
<div class="csharpcode">
<pre><span class="kwrd">public</span> <span class="kwrd">void</span> Use_GetArgumentsForCallsMadeOn_to_inspect_arguments()</pre>
</div>
<div class="csharpcode">
<pre>{</pre>
</div>
<div class="csharpcode">
<pre>    var interactor = <span class="kwrd">new</span> InteractingClass();</pre>
</div>
<div class="csharpcode">
<pre>    interactor.CallTheInterfaceTwice(_mock);</pre>
</div>
<div class="csharpcode">
<pre>    IList&lt;<span class="kwrd">object</span>[]&gt; argsPerCall = _mock.<strong>GetArgumentsForCallsMadeOn</strong>(m =&gt; m.MethodThatReturnsInteger(<span class="kwrd">null</span>));</pre>
</div>
<div class="csharpcode">
<pre>    argsPerCall[0][0].ShouldEqual(<span class="str">"foo"</span>);</pre>
</div>
<div class="csharpcode">
<pre>    argsPerCall[1][0].ShouldEqual(<span class="str">"bar"</span>);</pre>
</div>
<div class="csharpcode">
<pre>}</pre>
</div>
<p>Picture looked quite rosy here until I passed over excitement phase and entered phase of maintaining such software. <a href="http://www.refactoring.com/" target="_blank">Refactoring</a> such code became painful job now. That is precisely because I have my logic duplicated at two places, one in production code and one in test. Every single change that I make in production code has to be reflected into test interaction as well. This is direct violation of fundamental principle of OOP.  This indeed is one of the code-smell whose root is buried in wrong choice of underlying software design.</p>
<p>Now let’s step back and analyze what has gone wrong over this journey. Moving from state base test into interaction base test has its value under certain situation. However as we move towards “<strong>loosely coupled</strong>” and “<strong>highly cohesive</strong>” software architecture design, underlying elements are all services that works together to achieve given use case. Unit testing at those service level yields sweet fruit in terms of coverage and confidence in being able to refactor codebase at any give time. However there is little value in testing interaction between these services and their sequencing with much of mocks.</p>
<p align="justify">Big question that remains here then would be “How do I ensure those end to end scenarios are covered under test?”. Well, the answer is hidden inside question itself. Coverage on “End to end scenarios” needs “End to End” testing. That’s exact where  Integration test has real value to demonstrate. For the case of web page which let user fill in form and take some action, typically such integration test will include testing all but the actual UI layer. In language of <strong>CommandProcessor</strong> from <a href="http://mvccontrib.codeplex.com/" target="_blank">MvcContrib</a>, it is called PageTester.  Last but not least is UI Tests which ensures application level configuration and environment is set up correctly.</p>
<p>Till next time. Code smartly.</p>
<p>&nbsp;</p>
<p><em>Interested in Agile? Download a Copy of our Whitepaper &#8216;The Agile Difference&#8217;</em><br />
<span id="hs-cta-wrapper-a33cdb71-84c4-492f-8805-0e7cb7075845" class="hs-cta-wrapper"> <!--HubSpot Call-to-Action Code --> <span id="hs-cta-a33cdb71-84c4-492f-8805-0e7cb7075845" class="hs-cta-node hs-cta-a33cdb71-84c4-492f-8805-0e7cb7075845"> <a href="http://info.headspring.com/the-agile-difference--headspring-whitepaper"><img id="hs-cta-img-a33cdb71-84c4-492f-8805-0e7cb7075845" class="hs-cta-img" style="border-width: 0px;" src="//d1n2i0nchws850.cloudfront.net/portals/108832/51614d43-3f93-4b4a-a0ea-d8c22c601057-1313166962628/download-the-agile-difference.png?v=1313166962.9" alt="download-the-agile-difference" /></a><br />
</span><br />
<script type="text/javascript">// <![CDATA[
(function(){
  var hsjs = document.createElement("script");
     hsjs.type = "text/javascript";
     hsjs.async = true;
     hsjs.src = "//cta-service.cms.hubspot.com/cta-service/loader.js?placement_guid=a33cdb71-84c4-492f-8805-0e7cb7075845";
  (document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(hsjs);
  setTimeout(function() {document.getElementById("hs-cta-a33cdb71-84c4-492f-8805-0e7cb7075845").style.visibility="hidden"}, 1);
  setTimeout(function() {document.getElementById("hs-cta-a33cdb71-84c4-492f-8805-0e7cb7075845").style.visibility="visible"}, 2000);
})();
// ]]&gt;</script><br />
<!-- HubSpot Call-to-Action Code --><br />
<!-- hs-cta-wrapper --></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.headspring.com/2011/07/tdd-caveat-how-not-to-follow-test-driven-development/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.headspring.com @ 2012-05-18 12:53:11 -->
