<?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>Flexible Diamond</title>
	<atom:link href="http://blog.flexiblediamond.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexiblediamond.com</link>
	<description></description>
	<lastBuildDate>Wed, 02 Sep 2009 12:31:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What&#8217;s the point of all this mockery?</title>
		<link>http://blog.flexiblediamond.com/2009/08/whats-the-point-of-all-this-mockery/</link>
		<comments>http://blog.flexiblediamond.com/2009/08/whats-the-point-of-all-this-mockery/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 21:53:28 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=176</guid>
		<description><![CDATA[I&#8217;ve jumped in with both feet, without pausing to explain why I&#8217;m doing it &#8211; so, where do mock objects fit into my daily testing behaviours?

when the system under test relies on an expensive resource
when the system under test relies on a live resource
when the system under test relies on a resource that doesn&#8217;t yet [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve jumped in with both feet, without pausing to explain why I&#8217;m doing it &#8211; so, where do mock objects fit into my daily testing behaviours?</p>
<ul>
<li>when the system under test relies on an expensive resource</li>
<li>when the system under test relies on a live resource</li>
<li>when the system under test relies on a resource that doesn&#8217;t yet exist</li>
<li>when I want to ensure that the system under test uses the resource correctly</li>
</ul>
<p>I had to build a couple of client applications recently (twitter and flickr, since you ask &#8211; talk about re-inventing the wheel &#8230;), which interacted with what I consider expensive resources &#8211; firstly, I was contacting the remote flickr servers and awaiting their response each time I tested; secondly, the twitter API <a href="http://apiwiki.twitter.com/Rate-limiting">puts limits on how often it&#8217;s called</a>, which means that I could run out of calls pretty quickly if every test made at least one call, and all tests were run each time I compiled the movie.</p>
<p>A couple of years ago, we built a googlemaps-stylee flash app for a certain weekend-break company to allow users to choose chalets (/lodges/huts/accommodation units &#8211; bizarrely &#8216;accommodation units&#8217; was the official term) online. The units&#8217; availability was updated in real time, so the app had to query the server for the latest data. The only problem with this was that the server application was still under design &#8211; it didn&#8217;t yet exist.</p>
<p>I&#8217;ve also worked with database developers who haven&#8217;t yet finalised their DB structure, and who keep dropping and re-building the database, which means deleting all the data that my test scripts rely on.</p>
<p>You only need to experience difficulties such as these a couple of times to realise that it&#8217;s imperative to have control of the remote/live/non-existent/under-development resource in order for the tests to be of any use.</p>
<p>The good news is that &#8211; in most cases &#8211; it&#8217;s possible to define an API for communication with the resource even before it exists, and that&#8217;s what makes mock objects so useful &#8211; they can honour the API, thus enabling the code we build against the tests to work against the resource when it&#8217;s ready.</p>
<p>Strikes me an example might be useful. Twitter suit you?</p>
<p>I have a TwitterView object, which takes a TwitterProxy which in turn communicates with the Twitter servers. I know it&#8217;s terrible &#8211; aren&#8217;t these chaps supposed to be cleanly separated? The TwitterView receives an event when the proxy has done all its loading, and then can populate the relevant TextFields. Easy, innit.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterView <span class="kw3">extends</span> Sprite <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> title:<span class="kw3">TextField</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> tweets:<span class="kw3">TextField</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> proxy:ITwitterProxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterView<span class="br0">&#40;</span>proxy:ITwitterProxy = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">proxy</span> = proxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initView<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTitle<span class="br0">&#40;</span><span class="st0">&quot;Hello World!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> title.<span class="kw3">text</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> setTitle<span class="br0">&#40;</span>title:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">title</span>.<span class="kw3">text</span> = title;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> setTweets<span class="br0">&#40;</span>tweets:<span class="kw3">Array</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">tweets</span>.<span class="kw3">htmlText</span> = tweets.<span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\n</span><span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; override <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;[TwitterView]&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>proxy == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy = <span class="kw2">new</span> TwitterProxy<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TwitterLoadEvent.<span class="me1">TWITTER_LOADED</span>, onTwitterLoaded<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> initView<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>title<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tweets = <span class="kw2">new</span> <span class="kw3">TextField</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tweets.<span class="kw3">width</span> = <span class="nu0">500</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tweets.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tweets.<span class="kw3">wordWrap</span> = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tweets.<span class="me1">y</span> = title.<span class="me1">y</span> + title.<span class="kw3">height</span> + <span class="nu0">10</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>tweets<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> onTwitterLoaded<span class="br0">&#40;</span>event:TwitterLoadEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTitle<span class="br0">&#40;</span>event.<span class="me1">proxy</span>.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTweets<span class="br0">&#40;</span>event.<span class="me1">proxy</span>.<span class="me1">getTweets</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>In the onTwitterLoaded function, you can see the two most important calls that we need to make on the TwitterProxy: getTitle() and getTweets(). I put these in the ITwitterProxy interface.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw3">interface</span> ITwitterProxy <span class="kw3">extends</span> IEventDispatcher <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> getTweets<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Array</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>So now we have a fairly basic view, which expects its data from the proxy. </p>
<p>Let&#8217;s see it in action, courtesy of TwitterApp. Yep, not much happening:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterApp <span class="kw3">extends</span> Sprite <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterApp<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> view:TwitterView = <span class="kw2">new</span> TwitterView<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>view<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>We want to practise test-driven development &#8211; write a failing test > code until it passes > write another test > refactor &#8211; so we want to write a unit test that will check the view&#8217;s title and tweets, but (a) we can&#8217;t rely on the live twitter data as it will change over time, and (b) we don&#8217;t want to run up against the limit of API calls that we can make. Time for a mock object, methinks.</p>
<p>Firstly, I&#8217;m using <a href="http://asunit.org">ASUnit</a> rather than FlexUnit, so if you&#8217;re following along, you&#8217;ll need to grab that and the <a href="http://blog.hoardinghopes.com/index.php/2009/07/mockito-flex-meets-asunit/">ASUnitMockitoTestCase bridging class</a> that I published one or two articles ago. Let&#8217;s start with a skeleton testcase:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterTest <span class="kw3">extends</span> ASUnitMockitoTestCase <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterTest<span class="br0">&#40;</span>testMethod:<span class="kw3">String</span> = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#91;</span><span class="br0">&#93;</span>, testMethod<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> testBasic<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;failing test&quot;</span>, <span class="nu0">1</span> + <span class="nu0">1</span> == <span class="nu0">5</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Notice that we have a basic test that will show up as a fail in ASUnit, so that we can be sure that we&#8217;ve hooked everything together successfully. As soon as you see the fail, you can delete it. Note also that the call to super() starts with an empty Array &#8211; in time we&#8217;ll populate with the classes that we wish to set up as mocks.</p>
<p>Now, let&#8217;s pause for a think about what we want to test here &#8211; the View relies on the proxy for its data, so we want to check that the view gets its data successfully from the proxy <em>without hitting the live Twitter servers</em>. Oh, and the proxy doesn&#8217;t exist yet, just an interface.</p>
<p>I&#8217;m going to start really slowly here, forgive me &#8211; adding the assert that checks the view&#8217;s title.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterTest <span class="kw3">extends</span> ASUnitMockitoTestCase <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterTest<span class="br0">&#40;</span>testMethod:<span class="kw3">String</span> = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#91;</span><span class="br0">&#93;</span>, testMethod<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> testViewGetTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span>, view.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Immediate compile error, since we haven&#8217;t declared view, so let&#8217;s add another line: </p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> view:TwitterView = <span class="kw2">new</span> TwitterView<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">assertEquals<span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span>, view.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Still no success, because the TwitterView cannot be instantiated without a ITwitterProxy, which we don&#8217;t have, so let&#8217;s mock that (note that I&#8217;ve also added ITwitterProxy to the super() in the TwitterTest() constructor).</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterTest <span class="kw3">extends</span> ASUnitMockitoTestCase <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterTest<span class="br0">&#40;</span>testMethod:<span class="kw3">String</span> = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#91;</span>ITwitterProxy<span class="br0">&#93;</span>, testMethod<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> testViewGetTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> mockProxy:ITwitterProxy = mock<span class="br0">&#40;</span>ITwitterProxy<span class="br0">&#41;</span> as ITwitterProxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> view:TwitterView = <span class="kw2">new</span> TwitterView<span class="br0">&#40;</span>mockProxy<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span>, view.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Huzzah &#8211; the movie compiles and we get our failing test <img src='http://blog.flexiblediamond.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  For the record, mock() takes the interface and builds an object based on it that will record all calls made on its methods &#8211; it&#8217;s very, very clever.</p>
<p>First thing, let&#8217;s set the mockProxy up to give us the title string that we expect &#8211; add this line above the creation of the view:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>mockProxy.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This beautiful line of code says: if someone calls getTitle() on the mockProxy, the mockProxy will return &#8220;Twitter updates&#8221;. Isn&#8217;t that cool? Of course, that doesn&#8217;t help pass the test just yet.</p>
<p>The view is expecting to receive a TwitterLoadEvent from the proxy, triggering onTwitterLoaded(), so our mock object needs to have IEventDispatcher functionality. However, because the mockObject does so much weird stuff behind the scenes that I don&#8217;t have (and don&#8217;t want to have) a clue about, I&#8217;m going to attack this another way.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>mockProxy.<span class="me1">addEventListener</span><span class="br0">&#40;</span>any<span class="br0">&#40;</span><span class="br0">&#41;</span>, any<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">will</span><span class="br0">&#40;</span>fireImmediateLoadEvent<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>When mockProxy.addEventListener() is called, it will fire an immediate load event &#8211; this is mocking the request/response communication with the Twitter server. So what&#8217;s fireImmediateLoadEvent?</p>
<p>It&#8217;s a GenericAnswer object, which just holds a function that will be called when addEventListener() is called; in this case I want it to be like this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> fireImmediateLoadEvent:Answer = <span class="kw2">new</span> GenericAnswer<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// record the event and eventHandler somehow</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// then immediately fire the event with the required data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Of course, in the real world, the proxy will be doing this as part of its work, but because we&#8217;re using a mock proxy, we have to work around it a bit. I&#8217;ve come up with this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> d:EventDispatcher = <span class="kw2">new</span> EventDispatcher<span class="br0">&#40;</span><span class="br0">&#123;</span><span class="br0">&#125;</span> as IEventDispatcher<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> fireImmediateLoadEvent:Answer = <span class="kw2">new</span> GenericAnswer<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// record the event and eventHandler somehow</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; d.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TwitterLoadEvent.<span class="me1">TWITTER_LOADED</span>, view.<span class="me1">onTwitterLoaded</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// then immediately fire the event with the required data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; d.<span class="me1">dispatchEvent</span><span class="br0">&#40;</span><span class="kw2">new</span> TwitterLoadEvent<span class="br0">&#40;</span>mockProxy<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>So now the test looks like this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> testViewGetTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// create an EventDispatcher that can be used as the dispatching functionality for</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the mock ITwitterClient</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> d:EventDispatcher = <span class="kw2">new</span> EventDispatcher<span class="br0">&#40;</span><span class="br0">&#123;</span><span class="br0">&#125;</span> as IEventDispatcher<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> mockProxy:ITwitterProxy = mock<span class="br0">&#40;</span>ITwitterProxy<span class="br0">&#41;</span> as ITwitterProxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; given<span class="br0">&#40;</span>mockProxy.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; given<span class="br0">&#40;</span>mockProxy.<span class="me1">getTweets</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="br0">&#91;</span><span class="st0">&quot;Tweet#1&quot;</span>, <span class="st0">&quot;Tweet#2&quot;</span>, <span class="st0">&quot;Tweet#3&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> view:TwitterView = <span class="kw2">new</span> TwitterView<span class="br0">&#40;</span>mockProxy<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> fireImmediateLoadEvent:Answer = <span class="kw2">new</span> GenericAnswer<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// add the listening class</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TwitterLoadEvent.<span class="me1">TWITTER_LOADED</span>, view.<span class="me1">onTwitterLoaded</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// then immediately fire the event &#8211; this mocks the XML-loading that really occurs</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d.<span class="me1">dispatchEvent</span><span class="br0">&#40;</span><span class="kw2">new</span> TwitterLoadEvent<span class="br0">&#40;</span>mockProxy<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; given<span class="br0">&#40;</span>mockProxy.<span class="me1">addEventListener</span><span class="br0">&#40;</span>any<span class="br0">&#40;</span><span class="br0">&#41;</span>, any<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">will</span><span class="br0">&#40;</span>fireImmediateLoadEvent<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; view.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span class="br0">&#40;</span><span class="st0">&quot;Twitter updates&quot;</span>, view.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>For completeness, here&#8217;s TwitterLoadEvent:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> TwitterLoadEvent <span class="kw3">extends</span> Event <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const TWITTER_LOADED:<span class="kw3">String</span> = <span class="st0">&quot;onTwitterLoaded&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _proxy:ITwitterProxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> TwitterLoadEvent<span class="br0">&#40;</span>proxy:ITwitterProxy<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span>TWITTER_LOADED, <span class="kw2">false</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; _proxy = proxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> proxy<span class="br0">&#40;</span><span class="br0">&#41;</span>:ITwitterProxy <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> _proxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2009%2F08%2Fwhats-the-point-of-all-this-mockery%2F';
  addthis_title  = 'What%26%238217%3Bs+the+point+of+all+this+mockery%3F';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
<div id="wherego_related"><h3>Readers who viewed this page also viewed:</h3><ul><li><a href="http://blog.flexiblediamond.com/about/">About Us</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2009/08/whats-the-point-of-all-this-mockery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocking slavery</title>
		<link>http://blog.flexiblediamond.com/2009/07/mocking-slavery/</link>
		<comments>http://blog.flexiblediamond.com/2009/07/mocking-slavery/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 17:50:41 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=154</guid>
		<description><![CDATA[New to the idea of such mockery, I was very lucky to find a tutorial using the Java version which I could convert as I worked through it.
Now I&#8217;m converted &#8211; it&#8217;s a very neat and fast way of stubbing out the behaviours that I wish to code.
This morning, however, I came across a slightly [...]]]></description>
			<content:encoded><![CDATA[<p>New to the idea of such mockery, I was very lucky to find <a href="http://schuchert.wikispaces.com/Mockito.LoginServiceExample">a tutorial using the Java version</a> which I could convert as I worked through it.</p>
<p>Now I&#8217;m converted &#8211; it&#8217;s a very neat and fast way of stubbing out the behaviours that I wish to code.</p>
<p>This morning, however, I came across a slightly trickier case to mock &#8211; at least, a case that required trial and error, as it hasn&#8217;t been documented that fully.</p>
<p>I have a slave interface:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw3">interface</span> ISlave <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span> doSthg<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span> order<span class="br0">&#40;</span>command:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span> answer<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And the behaviour I want is that when a slave is ordered to &#8220;doSthg!&#8221;, it should answer() and doSthg() pretty sharpish. So the test looks like this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">slave.<span class="me1">order</span><span class="br0">&#40;</span><span class="st0">&quot;doSthg!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">verify<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">that</span><span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">verify<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">that</span><span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>To verify().that(slave.answer()) means to verify that slave.answer was called once.</p>
<p>First off, I needed to define the doSthg() and answer() methods, having created a mock slave from the interface (both return a String object):</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> slave:ISlave = mock<span class="br0">&#40;</span>ISlave<span class="br0">&#41;</span> as ISlave;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;done!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;yessir!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>And then I came to the tricky bit &#8211; since I&#8217;m creating this object out of an Interface definition how can I define the behaviour of slave.order()?</p>
<p>Well, thankfully the GenericAnswer object literally holds the answer to that question &#8211; it is instantiated with a function thus and given to the mock slave.order (if the call parameter is correct!):</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> answer:Answer = <span class="kw2">new</span> GenericAnswer<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">order</span><span class="br0">&#40;</span><span class="kw3">eq</span><span class="br0">&#40;</span><span class="st0">&quot;doSthg!&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">will</span><span class="br0">&#40;</span>answer<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>So now I have created an ISlave interface with three public methods, and defined how the methods interact, and precisely what parameter in order() will trigger the correct interaction. In full it looks like this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> slave:ISlave = mock<span class="br0">&#40;</span>ISlave<span class="br0">&#41;</span> as ISlave;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;done!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">willReturn</span><span class="br0">&#40;</span><span class="st0">&quot;yessir!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> answer:Answer = <span class="kw2">new</span> GenericAnswer<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">given<span class="br0">&#40;</span>slave.<span class="me1">order</span><span class="br0">&#40;</span><span class="kw3">eq</span><span class="br0">&#40;</span><span class="st0">&quot;doSthg!&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">will</span><span class="br0">&#40;</span>answer<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">slave.<span class="me1">order</span><span class="br0">&#40;</span><span class="st0">&quot;doSthg!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">verify<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">that</span><span class="br0">&#40;</span>slave.<span class="me1">answer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">verify<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">that</span><span class="br0">&#40;</span>slave.<span class="me1">doSthg</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>P.S. Obviously, the slave should not have a order() method &#8211; that&#8217;s the responsibility of the master (e.g. master.order(slave, &#8220;doSthg!&#8221;)), but it serves to make this example work, so forgive me!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2009%2F07%2Fmocking-slavery%2F';
  addthis_title  = 'Mocking+slavery';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
<div id="wherego_related"><h3>Readers who viewed this page also viewed:</h3><ul><li><a href="http://blog.flexiblediamond.com/2009/08/whats-the-point-of-all-this-mockery/">What&#8217;s the point of all this mockery?</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2009/07/mocking-slavery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mockito-Flex meets ASUnit</title>
		<link>http://blog.flexiblediamond.com/2009/07/mockito-flex-meets-asunit/</link>
		<comments>http://blog.flexiblediamond.com/2009/07/mockito-flex-meets-asunit/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 17:50:20 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=163</guid>
		<description><![CDATA[Well, that&#8217;s not a catchy headline, but it does pretty much sum it up. I&#8217;ve been playing with Mockito-Flex, a mock object framework for Actionscript 3. It&#8217;s great, and made vastly easier to pick up by a Mockito-FlexUnit bridge in the form of a MockitoTestCase that does the hard work of reporting the mocking results [...]]]></description>
			<content:encoded><![CDATA[<p>Well, that&#8217;s not a catchy headline, but it does pretty much sum it up. I&#8217;ve been playing with <a href="http://bitbucket.org/loomis/mockito-flex/wiki/Home">Mockito-Flex</a>, a <a href="http://en.wikipedia.org/wiki/Mock_object">mock object</a> framework for Actionscript 3. It&#8217;s great, and made vastly easier to pick up by a Mockito-FlexUnit bridge in the form of a MockitoTestCase that does the hard work of reporting the mocking results and validations in a way that FlexUnit can display.</p>
<p>Of course, <a href="http://opensource.adobe.com/wiki/display/flexunit/FlexUnit;">FlexUnit</a> does require the Flex framework, which bulks up the whole thing. Oh, and I&#8217;m used to using <a href="http://asunit.org">ASUnit</a>. So I&#8217;ve written the following class that does the same job as MockitoTestCase, but for ASUnit:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* The MIT License</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Copyright (c) 2009 Mockito contributors</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Permission is hereby granted, free of charge, to any person obtaining a copy of this software</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* subject to the following conditions:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">package org.<span class="me1">mockito</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> asunit.<span class="me1">framework</span>.<span class="me1">TestCase</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">mockito</span>.<span class="me1">api</span>.<span class="me1">Matcher</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">mockito</span>.<span class="me1">api</span>.<span class="me1">MethodSelector</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">mockito</span>.<span class="me1">api</span>.<span class="me1">MockCreator</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">mockito</span>.<span class="me1">api</span>.<span class="me1">Stubber</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">mockito</span>.<span class="me1">api</span>.<span class="me1">Verifier</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> ASUnitMockitoTestCase <span class="kw3">extends</span> TestCase <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _mockClasses:<span class="kw3">Array</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> mockito:Mockito;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> ASUnitMockitoTestCase<span class="br0">&#40;</span>mockClasses:<span class="kw3">Array</span>, testMethod:<span class="kw3">String</span> = <span class="kw2">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mockClasses = mockClasses;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span>testMethod<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Due to the asynchronous nature of the class generation</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* a test needs to execute from a callback function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> override <span class="kw2">function</span> run<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>mockito == <span class="kw2">null</span> <span class="sy0">&amp;&amp;</span> _mockClasses<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mockito = <span class="kw2">new</span> Mockito<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> superRun:<span class="kw2">Function</span> = <span class="kw3">super</span>.<span class="me1">run</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mockito.<span class="me1">prepareClasses</span><span class="br0">&#40;</span>_mockClasses, repositoryPreparedHandler<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> repositoryPreparedHandler<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; superRun<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span>.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Constructs mock object</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param clazz a class of the mock object</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param constructorArgs constructor arguments required to create mock instance</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param name a name used in various output</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return a mocked object</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> mock<span class="br0">&#40;</span>classToMock:<span class="kw2">Class</span>, <span class="kw3">name</span>:<span class="kw3">String</span> = <span class="kw2">null</span>, constructorArgs:<span class="kw3">Array</span> = <span class="kw2">null</span><span class="br0">&#41;</span>:<span class="kw3">Object</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">mock</span><span class="br0">&#40;</span>classToMock, <span class="kw3">name</span>, constructorArgs<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A starter function for verification of executions</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If you dont specify the verifier, an equivalent of times(1) is used.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param verifier object responsible for verification of the following execution</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> verify<span class="br0">&#40;</span>verifier:Verifier = <span class="kw2">null</span><span class="br0">&#41;</span>:MethodSelector</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">verify</span><span class="br0">&#40;</span>verifier<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A starter function for stubbing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param methodCallToStub call a method to stub as an argument</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return an object providing stubbing options</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> given<span class="br0">&#40;</span>methodCallToStub:<span class="sy0">*</span><span class="br0">&#41;</span>:Stubber</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">given</span><span class="br0">&#40;</span>methodCallToStub<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @private</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> <span class="kw3">get</span> mockCreator<span class="br0">&#40;</span><span class="br0">&#41;</span>:MockCreator</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Matches any argument including &lt;code&gt;null&lt;/code&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> any<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="sy0">*</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">any</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Equality matcher</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Example:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* verify(never()).that(system.login(eq(&quot;root&quot;)));</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;/listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">eq</span><span class="br0">&#40;</span>expected:<span class="sy0">*</span><span class="br0">&#41;</span>:<span class="sy0">*</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="kw3">eq</span><span class="br0">&#40;</span>expected<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A fluent interface for making sure call hasn&#39;t happened</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Example:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* verify(never()).that(operator.execute());</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;/listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> never<span class="br0">&#40;</span><span class="br0">&#41;</span>:Verifier</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">never</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A fluent interface for counting calls</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Example:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* verify(times(2)).that(operator.execute());</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;/listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> times<span class="br0">&#40;</span>expectedCallsCount:<span class="kw3">int</span><span class="br0">&#41;</span>:Verifier</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">times</span><span class="br0">&#40;</span>expectedCallsCount<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A fluent interface for custom matcher</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Example:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* verify().that(system.login(argThat(new HashOnlyCapitalLettersMatcher())));</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;/listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* A good practice is to create a matcher recording function somewhere and name it</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* after the matcher. It&#39;s important to return a wildcard from the function to let it</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* work with any arugment of the function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* function hasOnlyCapitalLetters():*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* {</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; argThat(new HashOnlyCapitalLettersMatcher());</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* }</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &lt;/listing&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> argThat<span class="br0">&#40;</span>matcher:Matcher<span class="br0">&#41;</span>:<span class="sy0">*</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> mockito.<span class="me1">argThat</span><span class="br0">&#40;</span>matcher<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I&#8217;ve built this against ASUnit3, and it appears to be running fine. As you can see, it&#8217;s release under the MIT license, as is Mockito-Flex. I&#8217;d appreciate any feedback that&#8217;s going, so have a play and let me know &#8230;</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2009%2F07%2Fmockito-flex-meets-asunit%2F';
  addthis_title  = 'Mockito-Flex+meets+ASUnit';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
<div id="wherego_related"><h3>Readers who viewed this page also viewed:</h3><ul><li><a href="http://blog.flexiblediamond.com/2008/06/testing-proxies-in-puremvc/">Testing Proxies in PureMVC</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2009/07/mockito-flex-meets-asunit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rocks into Gold</title>
		<link>http://blog.flexiblediamond.com/2008/12/rocks-into-gold/</link>
		<comments>http://blog.flexiblediamond.com/2008/12/rocks-into-gold/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 23:25:23 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[management]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[pipeline]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=81</guid>
		<description><![CDATA[Clarke Ching &#8211; whose work I&#8217;ve been reading for a while, is preparing to publish a short parable for these troubled times. Get in touch with him via this post, and grab a copy, after all the more weapons in our armoury, the better chance we have of winning the inevitable battles.

  addthis_url  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://clarkeching.blogs.com/">Clarke Ching</a> &#8211; whose work I&#8217;ve been reading for a while, is preparing to publish a short parable for these troubled times. <a href="http://www.clarkeching.com/2008/12/rocks-into-gold-a-credit-crunch-parable-for-people-who-build-software-for-a-living.html">Get in touch with him via this post</a>, and grab a copy, after all the more weapons in our armoury, the better chance we have of winning the inevitable battles.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F12%2Frocks-into-gold%2F';
  addthis_title  = 'Rocks+into+Gold';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/12/rocks-into-gold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wacky agile zealots are at it again</title>
		<link>http://blog.flexiblediamond.com/2008/11/67/</link>
		<comments>http://blog.flexiblediamond.com/2008/11/67/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 23:11:26 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[Stuff]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=67</guid>
		<description><![CDATA[This post reminded me of a long drive around Eastern Scotland at the start of this weekend.
I had a printout of the route from Aberdeen to Boat-Of-Garten from the AA website. Matt had his TomTom. Rather than shuffling papers, I agreed to use the gadget, so Matt tapped in Boat Of Garten, and off we [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dnicolet1.tripod.com/agile/index.blog?entry_id=1756631">This post</a> reminded me of a long drive around Eastern Scotland at the start of <a href="http://blog.hoardinghopes.com/index.php/2008/05/off-to-the-cairngormsoff-to-the-cairngorms/">this weekend</a>.</p>
<p>I had a printout of the route from Aberdeen to Boat-Of-Garten from the AA website. Matt had his TomTom. Rather than shuffling papers, I agreed to use the gadget, so Matt tapped in Boat Of Garten, and off we went.</p>
<p>Despite knowing that Aberdeen airport is northwest of the city, and that we would be driving further northwest still, I didn&#8217;t complain when the TomTom took us around Aberdeen and southward down the coast &#8211; after all, there was bound to be a good reason, wasn&#8217;t there.</p>
<p>We were also extremely hungry and looking for food as much as roadsigns. (Incidentally, we found the first ever chippy that&#8217;s asked me which of a selection of batters I&#8217;d like &#8211; how good is that?).</p>
<p>The mileage remaining got less and less, and we were still driving along a large clear road in a fairly low-lying area, but my suspicions were rising. When we found ourselves on the Dundee bypass, I knew something was up. The TomTom was taking us to a non-existent destination, which had added two hours to our journey.</p>
<p>Finally, we got onto the main road north, and hammered along in the gloaming. Fantastically for a southerner, the sky remained light until 11pm, so the driving wasn&#8217;t that painful. But, even so, we had a deadline: the B&#038;B owner wanted us there by 10pm, so we made a series of grovelling phone calls as we got closer and closer.</p>
<p>It stuck in my memory as just another random irritating drive until reading <a href="http://dnicolet1.tripod.com/agile/index.blog?entry_id=1756631">Those wacky agile zealots are at it again</a>, when the greater implications became clear.</p>
<p>Even when the route, timings, are as clear and as well-defined as they can possibly be, we still need to keep our eyes on the road, not just for rabbits and corners, but also to check that the route is correct (or, in this case, the destination).</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F11%2F67%2F';
  addthis_title  = 'Wacky+agile+zealots+are+at+it+again';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/11/67/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I want problems, not solutions!</title>
		<link>http://blog.flexiblediamond.com/2008/08/i-want-problems-not-solutions/</link>
		<comments>http://blog.flexiblediamond.com/2008/08/i-want-problems-not-solutions/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 10:39:11 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[management]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[pipeline]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=60</guid>
		<description><![CDATA[So, there I was, quietly listening into a conference call between a couple of clients on one side, and the account manager, project manager and me on the other.
We were going through a small project that we&#8217;d just completed for the purposes of getting sign-off. We had built in the functionality they wanted, using the [...]]]></description>
			<content:encoded><![CDATA[<p>So, there I was, quietly listening into a conference call between a couple of clients on one side, and the account manager, project manager and me on the other.</p>
<p>We were going through a small project that we&#8217;d just completed for the purposes of getting sign-off. We had built in the functionality they wanted, using the designs that they&#8217;d agreed to, so it was plain sailing.</p>
<p>And then the spanner.</p>
<p><span id="more-60"></span></p>
<p>Part of the project is a news article page with a sidebar listing other news articles. The client decided that he wanted to be able to filter these. &#8220;Could we add a couple of dropdowns listing the article categories?&#8221;.</p>
<p>That was the point when my anticipated reality and real reality diverged:<br />
- anticipated reality: AM says &#8220;Sure, we&#8217;ll have a think about the best way to implement filtering, and present a couple of options back to you&#8221;.<br />
- real reality: PM says &#8220;Right, we&#8217;re going to add a couple of dropdowns below the list, one for &#8216;projects&#8217; and one for &#8216;countries&#8217; and they&#8217;ll alter the article list you see&#8221;.</p>
<p>After the phone call, the PM asked me to go ahead with it. Eh? Shouldn&#8217;t we get a designer on the job &#8211; someone who knows about usability and interface design, perhaps?</p>
<p>I thought I&#8217;d won that little spat when the PM sloped off, but she got a tester who wants to be a designer to photoshop exactly what the AM had suggested on the phone. Bang went any hope of getting an expert in human computer interaction on the job.</p>
<p>The Account Manager&#8217;s defense is that we&#8217;re doing what the client wants. Well, I counter, that&#8217;s not good enough &#8211; despite <a href="http://blog.flexiblediamond.com/index.php/2008/05/a-grown-up-conversation/">my previous post</a> saying that we &#8220;pretend the client knows what they want&#8221;, we shouldn&#8217;t allow them to define the solution. Yes, sure that&#8217;s what the client thinks they want, but we are being paid to know better.</p>
<p>I may know what I want to eat when I go to a restaurant, but I still like to hear what the specials are, just in case there&#8217;s something even more exciting. I may even know how to cook the dish, but that doesn&#8217;t mean they&#8217;re going to allow me to roll my sleeves up and get to work in the kitchen. I am paying for the chef&#8217;s expertise, and for the satisfaction of delegating a whole bunch of thinking and labour so that I can enjoy the fruits.</p>
<p>Yes, the client should be right in there defining the problem. Then we should check it and redefine it, and again and again, until we&#8217;re absolutely clear about it. Then we should get an expert  (maybe a few, even, bringing different viewpoints together) to draw up a solution or two, and present those back to the client. &#8220;But it&#8217;s just a simple change&#8221; the AM cries, except that it isn&#8217;t, because it hasn&#8217;t been fully defined.</p>
<p>The wannabe-designer did a great mock-up, but couldn&#8217;t tell me how the functionality should work &#8211; there were different colours of text indicating selected states, but she didn&#8217;t know how that would work between the two dropdowns. In short, the solution wasn&#8217;t a solution. Meanwhile, the developers aren&#8217;t clear what they should be building, the project manager&#8217;s frustrated because she thinks that the project is now in development (well, she got us the designs, didn&#8217;t she?), and the account manager&#8217;s having to deal with an increasingly impatient client who thought the solution was defined over the phone.</p>
<p>If the client&#8217;s paying good money for our services, we should provide those services. That&#8217;s the clearest thing, isn&#8217;t it? We are digital experts: strategy, user experience, design, technical development. The client is an expert in marketing and sourcing quality work (I hope). One side should be bringing a problem, the other a set of solutions. Now, which is which?</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F08%2Fi-want-problems-not-solutions%2F';
  addthis_title  = 'I+want+problems%2C+not+solutions%21';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
<div id="wherego_related"><h3>Readers who viewed this page also viewed:</h3><ul><li><a href="http://blog.flexiblediamond.com/about/">About Us</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/08/i-want-problems-not-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Proxies in PureMVC</title>
		<link>http://blog.flexiblediamond.com/2008/06/testing-proxies-in-puremvc/</link>
		<comments>http://blog.flexiblediamond.com/2008/06/testing-proxies-in-puremvc/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 13:13:25 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=55</guid>
		<description><![CDATA[This post is prompted by Larry Marburger&#8217;s article, since I came across this problem a few weeks ago, and found a different solution.
The scenario
There&#8217;s this great new framework that you&#8217;re starting to use, and it&#8217;s persuaded you to turn a new leaf and unit-test your work as you go. First off, be warned this is [...]]]></description>
			<content:encoded><![CDATA[<p>This post is prompted by <a href="http://developmentastic.com/2008/06/09/flexunit-testing-puremvc-code/">Larry Marburger&#8217;s article</a>, since I came across this problem a few weeks ago, and found a different solution.</p>
<p><strong>The scenario</strong><br />
There&#8217;s <a href="http://www.puremvc.org">this great new framework</a> that you&#8217;re starting to use, and it&#8217;s persuaded you to turn a new leaf and unit-test your work as you go. First off, be warned this is all AS2.0, using <a href="http://www.asunit.org">asunit2.5</a>, because I&#8217;m still stuck in the dark ages <img src='http://blog.flexiblediamond.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><strong>The problem</strong><br />
PureMVC uses Proxy objects to access data from the model, which fire off Notifications (PureMVC-specific events) when the data is ready. However, in the case of a Proxy that loads XML before making its data available, how do we know when it&#8217;s ready to be tested?</p>
<p><span id="more-55"></span><br />
<strong>Solution </strong><br />
Mediator objects sign up to receive notification of Proxy events in PureMVC, so we can subclass the Mediator to create a class that can run tests on the Proxy.</p>
<p><strong>Example please</strong><br />
ASUnit calls <code>run()</code> for every TestCase in the TestSuite, the default implementation of which calls <code>runNow()</code> to run the tests within a class. So I&#8217;ve overridden <code>run()</code> to create the Proxy we want to test. When the Proxy is ready, it will notify the TestCase, and <code>runNow()</code> will be called.</p>
<p>In order to achieve this, I&#8217;ve created a TestHelper, which subclasses Mediator, to capture the Proxy&#8217;s completion Notification. The TestHelper tells the TestCase that it&#8217;s good to go, and <code>runNow()</code> gets called.</p>
<p><strong>A thousand words</strong></p>
<p><a href='http://blog.hoardinghopes.com/wp-content/uploads/2008/06/sequence.png'><img src="http://blog.hoardinghopes.com/wp-content/uploads/2008/06/sequence-300x214.png" alt="" title="Sequence for testing Proxies in PureMVC" width="300" height="214" class="alignnone size-medium wp-image-56" /></a></p>
<p><strong>Implementation Specifics</strong></p>
<p>First, the class we&#8217;re interested in, and as you can see, it&#8217;s very simple. It registers with the PureMVC ApplicationFacade for <code>Events.XML_LOADED</code> Notifications, and calls the responseHandler it was given by when created by NavigationProxyTest (<code>runNow()</code>).</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">import</span> org.<span class="me1">puremvc</span>.<span class="me1">as2</span>.<span class="me1">interfaces</span>.<span class="me1">IMediator</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">import</span> org.<span class="me1">puremvc</span>.<span class="me1">as2</span>.<span class="me1">interfaces</span>.<span class="me1">INotification</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">import</span> org.<span class="me1">puremvc</span>.<span class="me1">as2</span>.<span class="me1">patterns</span>.<span class="me1">mediator</span>.<span class="me1">Mediator</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">import</span> Events;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> NavigationProxyTestHelper <span class="kw3">extends</span> Mediator <span class="kw3">implements</span> IMediator <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">var</span> <span class="kw3">NAME</span>:<span class="kw3">String</span> = <span class="st0">&quot;NavigationProxyTestHelper&quot;</span>; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">private</span> <span class="kw2">var</span> _responseHandler:<span class="kw2">Function</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> NavigationProxyTestHelper<span class="br0">&#40;</span>view:<span class="kw3">Object</span>, <span class="kw3">name</span>:<span class="kw3">String</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="kw3">name</span> <span class="sy0">||</span> <span class="kw3">NAME</span>, view<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> listNotificationInterests<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Array</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="br0">&#91;</span>Events.<span class="me1">XML_LOADED</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> handleNotification<span class="br0">&#40;</span>notification:INotification<span class="br0">&#41;</span>:<span class="kw3">Void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span>notification.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">case</span> Events.<span class="me1">XML_LOADED</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _responseHandler<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> setResponseHandler<span class="br0">&#40;</span>response:<span class="kw2">Function</span><span class="br0">&#41;</span>:<span class="kw3">Void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; _responseHandler = response;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The NavigationProxyTest TestCase sets up the TestHelper in <code>run()</code>, and registers it with the ApplicationFacade. Then it creates the NavigationProxy instance that we want to test. When the Proxy is fully-loaded and raring to go, <code>TestCase#runNow()</code> will be called, which calls all methods starting &#8220;test&#8221; &#8211; so in this example <code>testValuesFromXML()</code>.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> NavigationProxyTest <span class="kw3">extends</span> TestCase <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">private</span> instance:NavigationProxy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> run<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> mediator:NavigationProxyTestHelper = <span class="kw2">new</span> NavigationProxyTestHelper<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">createEmptyMovieClip</span><span class="br0">&#40;</span><span class="st0">&quot;empty_mc&quot;</span>, <span class="nu0">1</span><span class="br0">&#41;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; NavigationProxyTestHelper.<span class="kw3">NAME</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; ApplicationFacade.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">registerMediator</span><span class="br0">&#40;</span>mediator<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; NavigationProxyTestHelper<span class="br0">&#40;</span>mediator<span class="br0">&#41;</span>.<span class="me1">setResponseHandler</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Delegate.<span class="me1">create</span><span class="br0">&#40;</span><span class="kw3">this</span>, runNow<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; instance = <span class="kw2">new</span> NavigationProxy<span class="br0">&#40;</span><span class="st0">&quot;navigation.xml&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">function</span> testValuesFromXML<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Void</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// initialDestination &amp; showIntroVideo are found in the XML that the NavigationProxy loads</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; assertEquals<span class="br0">&#40;</span><span class="st0">&quot;destinationID = 72&quot;</span>, <span class="nu0">72</span>, instance.<span class="me1">initialDestination</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; assertFalse<span class="br0">&#40;</span><span class="st0">&quot;showIntroVideo = true&quot;</span>, instance.<span class="me1">showIntroVideo</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F06%2Ftesting-proxies-in-puremvc%2F';
  addthis_title  = 'Testing+Proxies+in+PureMVC';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
<div id="wherego_related"><h3>Readers who viewed this page also viewed:</h3><ul><li><a href="http://blog.flexiblediamond.com/2009/07/mocking-slavery/">Mocking slavery</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/06/testing-proxies-in-puremvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A grown-up conversation</title>
		<link>http://blog.flexiblediamond.com/2008/05/a-grown-up-conversation/</link>
		<comments>http://blog.flexiblediamond.com/2008/05/a-grown-up-conversation/#comments</comments>
		<pubDate>Tue, 20 May 2008 17:02:56 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[management]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[business]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=51</guid>
		<description><![CDATA[Several places I&#8217;ve worked have spoken about the client in two contrasting ways: one, hushed tones suggesting that they&#8217;re too sensitive to handle whatever reality we&#8217;re dealing with; two, derision suggesting that they&#8217;re too much of an idiot to understand whatever reality we&#8217;re dealing with.
Both are clearly untrue (to greater or lesser degrees), and both [...]]]></description>
			<content:encoded><![CDATA[<p>Several places I&#8217;ve worked have spoken about <em>the client</em> in two contrasting ways: one, hushed tones suggesting that they&#8217;re too sensitive to handle whatever reality we&#8217;re dealing with; two, derision suggesting that they&#8217;re too much of an idiot to understand whatever reality we&#8217;re dealing with.</p>
<p>Both are clearly untrue (to greater or lesser degrees), and both serve to make our jobs harder because they distance us from the most important person in any project.</p>
<p>So here&#8217;s a list of questions I would like answered:</p>
<ul>
<li>why do we keep secrets from clients?</li>
<li>why are we so keen to promise tight deadlines?</li>
<li>why do we try to squeeze in extra stuff for them?</li>
<li>what if we treat them as part of the team?</li>
<li>what if we made them fully aware of the repercussions of their decisions?</li>
<li>what if we made demands of them, in order to deliver</li>
<li>what if we explain how risk builds up, and what they can do to mitigate it?</li>
</ul>
<p><span id="more-51"></span></p>
<p>I honestly don&#8217;t understand the prevailing attitude towards client in my industry &#8211; after all, we can view them as <em>the other</em>, or we can view them as our extension in another organisation, where they have their own set of clients that they are trying to satisfy. After all, we do what we do in order to succeed don&#8217;t we, to work our way up the ladder? If my job becomes one of enabling Joe Client to do well in his job, then he and I are allied with a common purpose, rather than sitting opposite each other across the client-agent divide (which is what creates the kind of attitudes I mentioned at the start).</p>
<p>So let&#8217;s pretend that clients know what they&#8217;re talking about, and that we are there to support them when they don&#8217;t. And let&#8217;s start down that path by having sensible grown-up conversations with them where we are open about the effect that they have on the success of the project.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F05%2Fa-grown-up-conversation%2F';
  addthis_title  = 'A+grown-up+conversation';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/05/a-grown-up-conversation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Project in distress (IV)</title>
		<link>http://blog.flexiblediamond.com/2008/05/project-in-distress-iv/</link>
		<comments>http://blog.flexiblediamond.com/2008/05/project-in-distress-iv/#comments</comments>
		<pubDate>Fri, 16 May 2008 09:25:12 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[management]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[distress]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=48</guid>
		<description><![CDATA[I particularly like this one: a week has passed, whilst the project manager has been &#8220;working&#8221; with the designer on the definition of 3D behaviour of playing cards on the site. His output landed in my in box yesterday afternoon: it was a list of cards, and the places they would sit in on the [...]]]></description>
			<content:encoded><![CDATA[<p>I particularly like this one: a week has passed, whilst the project manager has been &#8220;working&#8221; with the designer on the definition of 3D behaviour of playing cards on the site. His output landed in my in box yesterday afternoon: it was a list of cards, and the places they would sit in on the site. </p>
<p><em>This information was available in the original pitch document!</em> So has it really taken a week to change the document format?</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F05%2Fproject-in-distress-iv%2F';
  addthis_title  = 'Project+in+distress+%28IV%29';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/05/project-in-distress-iv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding out what&#8217;s best &#8230;</title>
		<link>http://blog.flexiblediamond.com/2008/05/finding-out-whats-best/</link>
		<comments>http://blog.flexiblediamond.com/2008/05/finding-out-whats-best/#comments</comments>
		<pubDate>Wed, 14 May 2008 21:20:14 +0000</pubDate>
		<dc:creator>jamesk</dc:creator>
				<category><![CDATA[management]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[pipeline]]></category>

		<guid isPermaLink="false">http://blog.hoardinghopes.com/?p=37</guid>
		<description><![CDATA[Just doing our best ain&#8217;t good enough &#8211; we need to be more savvy than that and work out precisely what&#8217;s the best thing to do first. So far, we&#8217;ve identified the conflict, and we now need to assess possible solutions.

If you haven&#8217;t read It&#8217;s not rocket science yet, please do first, as this article [...]]]></description>
			<content:encoded><![CDATA[<p>Just doing our best ain&#8217;t good enough &#8211; we need to be more savvy than that and work out precisely what&#8217;s the best thing to do first. So far, <a href="http://blog.hoardinghopes.com/index.php/2008/05/an-evaporating-conflict-cloud/">we&#8217;ve identified the conflict</a>, and we now need to assess possible solutions.</p>
<p><span id="more-37"></span></p>
<p>If you haven&#8217;t read <a href="http://blog.hoardinghopes.com/index.php/2008/05/its-not-rocket-science/"><em>It&#8217;s not rocket science</em></a> yet, please do first, as this article is a continuation of that theme.</p>
<p>I&#8217;ve said that key to a successful project is not just having everyone involved do their best, but having them work out what is the best thing to do, and then do their best at that. Anything else is at best a waste of effort, and at worst will doom a project.</p>
<p>I&#8217;ve also said that a sucessful project, just as any other system, needs a systemic view, rather than a bunch of local team views (new business, project management, creatives, developers, etc.).</p>
<p>So, how on earth do we go about finding out what&#8217;s best from a systemic perspective? A good place to start may be looking at some of the gripes that sit uncomfortably between teams involved in a project.</p>
<p>For example: </p>
<p><em>Project Manager </em>(PM): developers&#8217; estimates are always wrong.<br />
<em>Developer</em>: PMs treat our estimates as promises, and thus can&#8217;t handle it when they turn out to be inaccurate.</p>
<p>Let&#8217;s think about lines on a graph: x axis denotes time; y axis denotes understanding. At the very start of the project, my understanding of what&#8217;s involved is minimal. At the end of the project, I know all there is to know about it (ah, the beauty of hindsight!). Between those two points, the line rises in a sloping curve, with most altitude gained in the first half of the project.</p>
<p><a href='http://blog.hoardinghopes.com/wp-content/uploads/2008/05/time_vs_understanding.png'><img src="http://blog.hoardinghopes.com/wp-content/uploads/2008/05/time_vs_understanding.png" alt="" title="Understanding increasing over time" class="alignnone size-full wp-image-46" /></a></p>
<p>Where does estimation take place? Early on in the project, where understanding is incomplete (often requirements are incomplete too). </p>
<p><a href='http://blog.hoardinghopes.com/wp-content/uploads/2008/05/time_vs_understanding_vs_estimate.png'><img src="http://blog.hoardinghopes.com/wp-content/uploads/2008/05/time_vs_understanding_vs_estimate.png" alt="We estimate before we fully understand the project" title="Understanding over time" class="alignnone size-full wp-image-47" /></a></p>
<p>And that&#8217;s only the first problem. Here&#8217;s a second: when we estimate towards the start of a project for the length of a project, we&#8217;re looking far ahead into the future. The further we peer, the poorer our seeing, and the harder it is to a provide realistic estimate.</p>
<p><a href='http://blog.hoardinghopes.com/wp-content/uploads/2008/05/effect_of_change_on_estimates.png'><img src="http://blog.hoardinghopes.com/wp-content/uploads/2008/05/effect_of_change_on_estimates.png" alt="" title="How change breaks estimates" class="alignnone size-full wp-image-49" /></a></p>
<p>Estimating a project from the start requires long-distance lenses, so we may pad with a buffer because that protects us slightly. But, as the project progresses, problems arise, change requests come through, and the specification that we&#8217;ve been working from changes (or it doesn&#8217;t, even though the functionality does, but that&#8217;s another problem). This is how reality departs from our estimates. Towards the end of the project, we&#8217;re dealing with bugs that we couldn&#8217;t foresee and test results have come in, which frequently mean lots of change requests now that the client&#8217;s seen the proposed release version.</p>
<p>Two problems: estimating when our knowledge about the project is less than complete; changes arising that throw the project off schedule. Now what could solve them?</p>
<p>We want our estimates to be more accurate, so they can be considered commitments; and we want to be able to handle changes and problems that arise.</p>
<p>Imagine that, as a developer, you were asked each morning how long it would take to perform the single task you were about to tackle. Your response would be in hours, and probably more or less accurate. Imagine now, that you were given the whole list of tasks up front and asked to estimate on them &#8211; the answer would be in days, and a lot less accurate.</p>
<p>Firstly, say it takes 10 hours to complete a task, and you&#8217;re 10% out: it takes 11 hours. We&#8217;ve lost an hour. Say it takes 10 days, with the same margin of error, and it&#8217;s taken 11 days. Say it takes 100 days, and it&#8217;s taken 110 days. Thus the same margin of error, when affecting differing timescales, has very different ramifications. And just in case you think I&#8217;m being unfair by swapping from hours to days: if you think something will take one hour and I think it&#8217;ll take two, we have room for a discussion &#8211; the difference is clear; if you think something will take 30 hours and I think it&#8217;ll take 31, it&#8217;s a lot harder to explain the difference and decide which is a better estimate.</p>
<p>If we can make our estimates more often and more short-sighted, rather than a single one tackling the whole project, we stand a much better chance of getting the estimates right, we can adjust them based on recent learnings, and we can incorporate changes/problems as they arise.</p>
<p>That may resolve the conflict of PMs wanting commitments and developers not having concrete specs to work from (with no changes, ever ever). Whaddya think?</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.flexiblediamond.com%2F2008%2F05%2Ffinding-out-whats-best%2F';
  addthis_title  = 'Finding+out+what%26%238217%3Bs+best+%26%238230%3B';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexiblediamond.com/2008/05/finding-out-whats-best/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
