<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Marvellous Mechanical Mouse Organ</title>
	<atom:link href="http://fintanp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fintanp.wordpress.com</link>
	<description>Start Braindump. Error: Brain not found.</description>
	<lastBuildDate>Tue, 04 Jan 2011 14:16:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fintanp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Marvellous Mechanical Mouse Organ</title>
		<link>http://fintanp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fintanp.wordpress.com/osd.xml" title="The Marvellous Mechanical Mouse Organ" />
	<atom:link rel='hub' href='http://fintanp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>NaNoWriMo 2007: Half-way</title>
		<link>http://fintanp.wordpress.com/2007/11/15/nanowrimo-2007-half-way/</link>
		<comments>http://fintanp.wordpress.com/2007/11/15/nanowrimo-2007-half-way/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 23:26:02 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[NaNoWriMo]]></category>
		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/11/15/nanowrimo-2007-half-way/</guid>
		<description><![CDATA[It&#8217;s the half-way point of the NaNoWriMo and I&#8217;m still at it1. Week one was fantastic with the over 11 thousand words falling into place in the first two session. The first day came in at 3500 words and the second at a little over 8000. After that things slowed down a bit but I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=102&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://fintanp.files.wordpress.com/2007/10/nano_participant_icon_small.gif?w=500" alt="NaNoWriMo 2007" align="left" />It&#8217;s the half-way point of the <a href="http://www.nanowrimo.org/" target="_blank">NaNoWriMo</a> and I&#8217;m still at it<sup>1</sup>.  Week one was fantastic with the over 11 thousand words falling into place in the first two session.  The first day came in at 3500 words and the second at a little over 8000.  After that things slowed down a bit but I still managed to average above the target of 1667 words a day.  That&#8217;s just as well because I missed a few days in week one and the last week has been something of a bust with only two days writing done in the last seven days. Right now I&#8217;m across the 20k barrier<sup>2</sup> and just short of the 25 thousand half-way mark. I&#8217;m pretty happy with the way things are going though and reckon I&#8217;ll be back on target by the end of Sunday.</p>
<p>It definitely needs editing and trimming and I can already see ways in which inconsistencies have crept in.  I&#8217;ve also managed to introduce a little sub-plot which right now seems to have absolutely no purpose and I&#8217;ve completely failed to establish certain things about my central character which are important.</p>
<p>I can fix all that next month though.  For now it&#8217;s about getting the 50,000 words done even if they do edit down to about 20,000!</p>
<p>On the practical side I&#8217;ve been doing all the writing on my MacBook using <a href="http://www.jerssoftwarehut.com/" target="_blank">Jer&#8217;s Novel Writer</a>.  It&#8217;s a pretty good tool but it&#8217;s had a few revisions recently which broke and then fixed the word count.  The annoying part was that I wasn&#8217;t able to get onto the message board to report the bug.  I had to register but I&#8217;m still waiting for my confirmation email so I can log in.  Boo!</p>
<p>The daily word count which I enthusiastically tweet about <a href="http://twitter.com/fintanp" target="_blank">on Twitter</a> is based on the figure reported by Jer&#8217;s Novel Writer.  My daily totals were based on the word count that <a href="http://www.neooffice.org" target="_blank">NeoOffice</a> reports<sup>3</sup>.  Today I started using the NaNoWriMo word count utility and discovered that it doesn&#8217;t agree with what NeoOffice says.  I&#8217;m going to go with what NaNoWriMo say &#8211; they&#8217;re the ones deciding whether I&#8217;ve passed or not.</p>
<p>I&#8217;m something of a notorious procrastinator so one way in which I warm up before starting a session is to do some deliberate procrastination.  I check my mail, read my RSS feeds and look for any missed tweets on Twitter.  I spend about 20 or 30 minutes just generally browsing the web and then get started.  I&#8217;ve also done most of my writing in my dining room rather that at the desk in my study.  I reckon there are too many distractions in there<sup>4</sup> and if I sit at the end of the dining table I can actually put my feet up on the other chairs.  I&#8217;m almost in a reclining position as I write.</p>
<p>I&#8217;m looking good in good shape to hit the 50,000 word target at the moment but part of me secretly hopes that 50,000 words won&#8217;t be enough to actually finish this thing and I&#8217;ll have to keep going through December too!</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; Yay!<br />
2 &#8211; You can track my word count on the right side of the page&#8230;<br />
3 &#8211; I&#8217;ve been exporting from Jer&#8217;s Novel Writer to an RTF file after each session. Backup, backup, backup.<br />
4 &#8211; You can never re-read the entire <a href="http://en.wikipedia.org/wiki/Preacher_(comics)" target="_blank">Preacher series</a> too many times.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/102/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/102/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=102&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/11/15/nanowrimo-2007-half-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/nano_participant_icon_small.gif" medium="image">
			<media:title type="html">NaNoWriMo 2007</media:title>
		</media:content>
	</item>
		<item>
		<title>Technology Memory Lane</title>
		<link>http://fintanp.wordpress.com/2007/11/13/technology-memory-lane/</link>
		<comments>http://fintanp.wordpress.com/2007/11/13/technology-memory-lane/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 12:59:21 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Devices]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/11/13/technology-memory-lane/</guid>
		<description><![CDATA[I found a great site the other day and it took me on a real stroll down memory lane. It&#8217;s a bit nerdy, and probably appeals to the OCD aspect of my personality1, but Walkman Central has a list of all the Walkmans that Sony have produced. The two that really struck a synapse in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=103&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://fintanp.tumblr.com/post/18310796">I found a great site the other day</a> and it took me on a real stroll down memory lane.  It&#8217;s a bit nerdy, and probably appeals to the OCD aspect of my personality<sup>1</sup>, but <a href="http://www.walkmancentral.com/">Walkman Central</a> has a list of all the Walkmans that Sony have produced.  The two that really struck a synapse in the old long term memory were <a href="http://www.walkmancentral.com/products/wm-102">the WM-102</a> and the earlier <a href="http://www.walkmancentral.com/products/wm-10">WM-10</a>.</p>
<p><span id="more-103"></span>A mate of mine in school had the WM-10 and I loved how small it was. It was the same size as a cassette case but it expanded a little wider when you wanted to actually put a tape into it.  The WM-102, which came out a couple of years later, went a bit further.  It took the battery out of the body altogether and stuck it in a little box on the bottom.  You could either use the slim rechargeable one or a standard AA battery.  With the rechargable one the whole package was super small and genuinely the same size as a cassette case.</p>
<p><a href="http://fintanp.files.wordpress.com/2007/11/sony-wm-102.png" title="Sony WM-102"><img src="http://fintanp.files.wordpress.com/2007/11/sony-wm-102.png?w=250" alt="Sony WM-102" align="left" width="250" /></a>This picture here<sup>2</sup> is what you got in the pack.  I bought mine in 1987, the year they came out, with the winnings from a lottery scratch card.  I can&#8217;t remember how much it cost but I seem to remember having to put some money towards the £100<sup>3</sup> that I won.  Finding this site really brought back some memories of old-school<sup>4</sup> technology envy.</p>
<p>It also made me remember just how dominant Sony were in the portable music player space at the time.  Sure there were other manufacturers like Aiwa and Akai but Sony were top dog.  It always amazes me how they completely blew the portable music space when MP3 came along.  They seemed to be so busy fighting the change in the way people were listening to music that they didn&#8217;t produce a digital music player until very late in the game.  Even then they refused to support MP3, presumably because they were afraid of piracy issues, and instead came up with their own &#8220;standard&#8221; ATRAC.</p>
<p>Friends of mine came back from New York recently where they each bought themselves one of <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.apple.com/ipodtouch/">these beauties</a> which I think are fantastic.  Just as soon as I can find some spare cash to spend on one of them I will<sup>5</sup>. Still, I have fond memories of my trendy little Walkman from the 1980s for a lot of different reasons and I&#8217;m sure Sony do too.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; You should see me unstack and restack a dishwasher to get everything in order.  I scare myself sometimes.<br />
2 &#8211; Shamelessly nicked from <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://cgi.ebay.at/SONY-WALKMAN-WM-102-mit-Tasche-Anleitung-und-Ladegeraet_W0QQitemZ250182740826QQihZ015QQcategoryZ19636QQcmdZViewItem">a sale on the Austrian EBay site</a>.<br />
3 &#8211; A princely sum in 1987, especially when you&#8217;re 17.<br />
4 &#8211; At school!<br />
5 &#8211; God knows when the iPhone will reach Ireland&#8230;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/103/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/103/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=103&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/11/13/technology-memory-lane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/11/sony-wm-102.png" medium="image">
			<media:title type="html">Sony WM-102</media:title>
		</media:content>
	</item>
		<item>
		<title>Tumblr has Tumbled&#8230;</title>
		<link>http://fintanp.wordpress.com/2007/11/03/tumblr-has-tumbled/</link>
		<comments>http://fintanp.wordpress.com/2007/11/03/tumblr-has-tumbled/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 16:41:30 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Blogging]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/11/03/tumblr-has-tumbled/</guid>
		<description><![CDATA[Well it looks like Tumblr has died for the moment. They did a big upgrade on November 1st but for some reason either completely failed to test it or there were some nasty bugs hiding in the long grass. Whichever it is the RSS import feature was broken, then sort of fixed, then sort of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=100&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src='http://fintanp.files.wordpress.com/2007/11/tumblr-tumbled.png?w=500' alt='Tumblr Tumbled' align="left" />Well it looks like <a href="http://www.tumblr.com">Tumblr</a> has died for the moment.  They did a big upgrade on November 1st but for some reason either completely failed to test it or there were some nasty bugs hiding in the long grass.  Whichever it is the RSS import feature was broken, then sort of fixed, then sort of broken while all the time different pages were available/unavailable due to maintenance<sup>1</sup>.  Now it&#8217;s down completely and looks like it has been down all day.</p>
<p><span id="more-100"></span>It&#8217;s a pity because I really like the service, especially the way I could almost treat it as an aggregator for <a href="http://del.icio.us/fintanp">my del.icio.us links</a> and snippets of my blog entries.  I didn&#8217;t like the way it pulled in all <a href="http://twitter.com/fintanp">my tweets from Twitter</a><sup>2</sup> so I&#8217;d created a simple but nifty pipe on <a href="http://pipes.yahoo.com">Yahoo! Pipes!</a> to filter out replies to other people and remove the leading &#8220;fintanp:&#8221; and imported that as a regular RSS feed.  I hadn&#8217;t started pulling in <a href="http://flickr.com/photos/fintanp/">photos from Flickr</a> yet<sup>3</sup> but did post the occasional one taken with my phone.  I hope they fix it soon or I&#8217;ll have to move to a competitor like <a href="http://www.soup.io/">these guys</a>.</p>
<p>The last couple of days have made me realise just how reliant I am on hosted services like wordpress.com for this blog.  I&#8217;m going to have to organise my own soon.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; I could get the dashboard but couldn&#8217;t see the actual page&#8230; then I couldn&#8217;t see the dashboard but could see the page&#8230;. *sigh*.<br />
2 &#8211; Or how they were formatted.<br />
3 &#8211; I haven&#8217;t really started using flickr yet.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/100/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/100/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/100/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=100&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/11/03/tumblr-has-tumbled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/11/tumblr-tumbled.png" medium="image">
			<media:title type="html">Tumblr Tumbled</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrofitting Unit Tests Part 4 &#8211; Complex Test, Complex Code</title>
		<link>http://fintanp.wordpress.com/2007/11/02/retrofitting-unit-tests-part-4-complex-test-complex-code/</link>
		<comments>http://fintanp.wordpress.com/2007/11/02/retrofitting-unit-tests-part-4-complex-test-complex-code/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 13:18:21 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/11/02/retrofitting-unit-tests-part-4-complex-test-complex-code/</guid>
		<description><![CDATA[Picture by Olivander Some rights reserved. Having introduced mock objects, even if you’ve managed to avoid the pitfalls described in the previous posts in this series, you can often end up with some pretty complex and ugly-looking unit tests. There might be a lot of mock objects doing very little or there may be a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=90&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table class="image" align="left" width="180">
<tr>
<td><img width="180" src="http://fintanp.files.wordpress.com/2007/10/snow-mobile.jpg?w=180" alt="Snow Speeder" style="border:medium none;" /></td>
</tr>
<tr>
<td class="caption"><font color="gray" size="-2">Picture by <a href="http://flickr.com/photos/olivander/" target="_blank">Olivander</a><br />
<a href="http://creativecommons.org/licenses/by-nc-sa/2.0/" target="_blank"><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif?w=500" alt="Attribution" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_noncomm_small.gif?w=500" alt="Non-Commercial" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif?w=500" alt="Share Alike" align="middle" /></a><a href="http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en-us" target="_blank">Some rights reserved.</a></font></td>
</tr>
</table>
<p>Having introduced mock objects, even if you’ve managed to avoid the pitfalls described in the <a href="http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/">previous</a> <a href="http://fintanp.wordpress.com/2007/10/23/retrofitting-unit-tests-part-3-mock-object-hell/">posts</a> in this series, you can often end up with some pretty complex and ugly-looking unit tests.  There might be a lot of mock objects doing very little or there may be a lot of configuration required for the test.  Fight the urge to blame the unit test though.  If the unit test is complex, chances are it&#8217;s because the underlying code is complex.</p>
<p>For example, you might find yourself creating multiple mock objects simply to reproduce this pattern;</p>
<pre>
    classA.getB().getC().getD().doSomethingWithD();
</pre>
<p><span id="more-90"></span>In order to mock the invocation of the class D method you end up with something that looks like this if you’re using EasyMock:</p>
<pre>
    A mockA = createMock(A.class);
    B mockB = createMock(B.class);
    C mockC = createMock(C.class);
    D mockD = createMock(D.class);

    expect(mockA.getB()).andReturn(mockB);
    expect(mockB.getC()).andReturn(mockC);
    expect(mockC.getD()).andReturn(mockD);
    expect(mockD.doSomethingWithD()).andReturn(true);
</pre>
<p>It gets worse if this pattern repeats itself throughout the code.  If it does though it’s probably a code smell and more than likely indicates some potential refactoring of the underlying code.  Apply the <a href="http://www.refactoring.com/catalog/removeMiddleMan.html" target="_blank">Remove Middle Man</a> refactoring and go to this:</p>
<pre>
    classA.doSomething();    // Delegates to doSomethingWithD
</pre>
<p>The setup for your mock object in your unit test reduces to:</p>
<pre>
    A mockA = createMock(A.class);
    expect(mockA.doSomething()).andReturn(true);
</pre>
<p>Refactoring as you go while implementing your tests will help reduce this kind of complexity but be careful! Without a unit test in place for regression testing you may actually introduce bugs without realising it.  The general rule for writing unit tests applies: get your test working, refactor the code a little, refactor the test a little and make sure nothing is broken.</p>
<p>Your best bet may be to get a working unit test regardless of how complex it is without any significant refactoring of the code under test and then refactor<sup>1</sup>.  This way you’ll have a test which can be used to do regression testing.  Later you can refactor the code being tested and you’ll then be able to refactor the test, simplifying that too.</p>
<p>Having said all that be very aware that you may be overcomplicating your test with your use of mocks and may end up hiding the real test in a pile of mock object expectations.  This is where the use of stubs as opposed to mocks can come in handy, especially if refactoring is not an option<sup>2</sup>.  Instead of creating a set of mock objects and setting up their expected method calls, you create stub versions of the collaborator classes which have canned responses to method invocations.  You might find that these can then be re-used throughout your tests, simplifying them greatly.</p>
<p>Using my previous example, we might create a stub version of A in the following way:</p>
<pre>
    public class StubA implements A {
        private B stubB;

        public StubA(B stubB) {
            this.stubB = stubB;
        }

        @Override
        public B getB() {
            return stubB;
        }

        // Other interface methods are implemented as well and
        // can either return dummy values or throw exceptions.
    }
</pre>
<p>This of course assumes that A is an interface or can be extended with all of it&#8217;s public methods being overridden.  Don&#8217;t forget that the whole point of the exercise is to test code in isolation of the actual implementation of A.  We just want our stub implementation to return dummy values or throw exceptions for methods we don&#8217;t want (or expect) to be called.</p>
<p>Assuming that the stub versions of B and C look something similar, the setup of our test now looks something like:</p>
<pre>
    // This is the only mock object - it's the
    // real thing we're looking to happen.
    D mockD = createMock(D.class);
    expect(mockD.doSomethingWithD()).andReturn(true);

    // Here come the stubs which just enable our test.
    A classA = new StubA(new StubB(new StubC(mockD))));
</pre>
<p>Now when the code under test does this&#8230;</p>
<pre>
    classA.getB().getC().getD().doSomethingWithD();
</pre>
<p>&#8230;our stubs will provide the mock object which will be invoked to do the real work.</p>
<p>The nice thing about this is that because we don&#8217;t care about how A, B and C get used we don&#8217;t have to create mock objects.  On top of that, if these objects are used in the same way in multiple tests then my stub implementations can be re-used making the whole test suite a lot simpler.</p>
<p>I reckon it&#8217;s largely a judgement call on when to use mocks or stubs and it&#8217;s one that probably only really comes with experience<sup>3</sup>.  In my mind though there’s nothing wrong with starting out with a complex unit test full of mock objects, refactoring the code and then refactoring the test to simplify it all, including replacing mock objects with stubs.</p>
<p>In the next part of this series I’ll show how complexity can also be a result of “engineered bugs”.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; Assuming you can get the test working in the first place without refactoring.<br />
2 &#8211; The example in this post is based on some real-world code I&#8217;ve been looking at recently and is an obvious candidate for refactoring.  Your mileage may vary.<br />
3 &#8211; You weren&#8217;t expecting any easy answers were you?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/90/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/90/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=90&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/11/02/retrofitting-unit-tests-part-4-complex-test-complex-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/snow-mobile.jpg" medium="image">
			<media:title type="html">Snow Speeder</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif" medium="image">
			<media:title type="html">Attribution</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_noncomm_small.gif" medium="image">
			<media:title type="html">Non-Commercial</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif" medium="image">
			<media:title type="html">Share Alike</media:title>
		</media:content>
	</item>
		<item>
		<title>Going Dark For November</title>
		<link>http://fintanp.wordpress.com/2007/10/30/going-dark-for-november/</link>
		<comments>http://fintanp.wordpress.com/2007/10/30/going-dark-for-november/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 21:22:01 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[NaNoWriMo]]></category>
		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/30/going-dark-for-november/</guid>
		<description><![CDATA[Between the number of posts I churned out over last few weeks, and the spike in traffic after my recent post1 on Enterprise Ireland and Auctomatic, I&#8217;ve managed to break a lot of the mouse organ&#8217;s records2 this month. That&#8217;s probably going to change over the next few weeks though because I&#8217;ll be going dark [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=97&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://fintanp.files.wordpress.com/2007/10/nano_participant_icon_small.gif?w=500" alt="NaNoWriMo 2007" align="left" />Between the number of posts I churned out over last few weeks, and the spike in traffic after my recent post<sup>1</sup> on <a href="http://fintanp.wordpress.com/2007/10/16/unenterprising-ireland/">Enterprise Ireland and Auctomatic</a>, I&#8217;ve managed to break a lot of the mouse organ&#8217;s records<sup>2</sup> this month.  That&#8217;s probably going to change over the next few weeks though because I&#8217;ll be going dark for November.  I won&#8217;t be completely silent as I hope to post a few short pieces from time to time and I already have a few posts lined up.</p>
<p>The reason I&#8217;ll be going dark is that I&#8217;ve decided to take part in this years <a href="http://www.nanowrimo.org/" target="_blank">NaNoWriMo</a> challenge.  I&#8217;m probably mad because I&#8217;ve just looked at my calendar for the month of November and I reckon that between a trip to France in the middle of the month and a visit from my U.S.-based mum (plus a bunch of other stuff) I really only have two and a half weeks to write my 50,000 word novel.  This should be fun.</p>
<p>But sod it I&#8217;ve been planning this for a year so I&#8217;m going to do it.  I&#8217;ll keep you posted on how I&#8217;m getting on.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; A <a href="http://fintanp.wordpress.com/2007/10/17/unenterprising-ireland-correction/">somewhat inaccurate post</a> it has to be said.<br />
2 &#8211; Not that this would have been hard.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/97/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/97/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=97&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/30/going-dark-for-november/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/nano_participant_icon_small.gif" medium="image">
			<media:title type="html">NaNoWriMo 2007</media:title>
		</media:content>
	</item>
		<item>
		<title>WTF 2.0</title>
		<link>http://fintanp.wordpress.com/2007/10/24/wtf-20/</link>
		<comments>http://fintanp.wordpress.com/2007/10/24/wtf-20/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 09:36:55 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Web2.0]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/24/wtf-20/</guid>
		<description><![CDATA[I’ve never been particularly comfortable with the Web 2.0 label that seems to get applied to everything these days. It’s probably one of the most overused and misapplied marketing labels I’ve ever come across in my experience in the software industry. At least during the dot-com boom you knew what people were talking about &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=94&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://fintanp.files.wordpress.com/2007/10/reflectwtf-20beta.png?w=500" alt="WTF 2.0 (beta)" align="left" />I’ve never been particularly comfortable with the Web 2.0 label that seems to get applied to  everything these days.  It’s probably one of the most overused and misapplied marketing labels I’ve ever come across in my experience in the software industry.  At least during the dot-com boom you knew what people were talking about &#8211; using the web to sell stuff to people<sup>1</sup>.</p>
<p>What is the accepted definition of Web 2.0 anyway<sup>2</sup>? In a very real sense it’s a term that was coined by Tim O’Reilly to sell convention space.  As he said in <a href="http://radar.oreilly.com/archives/2007/10/web_30_semantic_web_web_20.html" target="_blank">this article</a> recently:<br />
<span id="more-94"></span><br />
<blockquote>Web 2.0 started out as the name of a conference! And that name had a very specific purpose: to signify that the web was roaring back after the dot com bust! The 2.0 bit wasn&#8217;t about the technology, but about the resurgence of interest in the web.</p></blockquote>
<p>And yet people insist on talking about being &#8220;Web 2.0&#8243; and having &#8220;Web 2.0&#8243; elements whether it&#8217;s some kind of social networking<sup>3</sup> thingy, using a bit of AJAX for a more interactive browser experience or just having <a href="http://h-master.net/web2.0/" target="_blank">a fancy reflective logo</a> and a nice colour scheme.  I’m reminded of an old boss of mine who, back in the very early ‘90s, wanted to know if our product was “client-server”.  He couldn’t define what he meant by that but it was obvious that he wanted to go out to customers and impress them with the fact that we supported the latest industry buzzwords<sup>4</sup>.  The same is true with Web 2.0. People have heard of it so they feel that have be doing it&#8230;  whatever &#8220;it&#8221; is.</p>
<p>The worst part about all of this is that the &#8220;2.0&#8243; part of Web 2.0 is now being applied to other things like <a href="http://blog.publish2.com/" target="_blank">publishing</a>, <a href="http://giving20.wordpress.com/" target="_blank">charity</a> and <a href="http://www.lunch20.com/">something called Lunch 2.0</a> which I guess is some kind of networking thing<sup>5</sup>.  Hell even movies are getting in on the act with Die Hard 4.0<sup>6</sup> aping the theme.  Does that mean there’s going to be a Die Hard 4.1? What’s that? The directors cut?<sup>7</sup></p>
<p>Yesterday I saw one that really took the biscuit:  <a href="http://www.centernetworks.com/california-fires-social-media" target="_blank">Firestorm 2.0</a></p>
<p>Now I know that this is referring to a collection of &#8220;social networking&#8221; sites where &#8220;user generated content&#8221; is being used to track the fires currently devastating parts of California but really! Stop 2.0! Enough Already 2.0!</p>
<p>There’s a lot of really cool stuff going on right now, some of which has changed the way we&#8217;ll use the web forever but the more I see this kind of thing the more I definitely think we’re in a bubble.  It may be different to the dot-com one but it’s a bubble nonetheless and that is bringing the marketing bandwagon jumpers out of the woodwork.  It gets worse when some people are now trying to define Web 3.0, sometimes in terms of <a href="http://www.calacanis.com/2007/10/03/web-3-0-the-official-definition/" target="_blank">their own product</a> much to <a href="http://avc.blogs.com/a_vc/2007/10/web-30-nonsense.html" target="_blank">people&#8217;s dismay</a>.</p>
<p>We may very well need a label to describe the period were going through in terms of the changes in how the Internet in general and the web in particular are being used.  The name &#8220;Web 2.0&#8243; may fill that role but can we stop using a non-specific inexact term in a very specific way?</p>
<p>&#8211; Fintan 1.0</p>
<hr />1 &#8211; Even if no-one would ever want to buy online what you were selling.<br />
2 &#8211; Is there one?!<br />
3 &#8211; Another entry in the buzzword bingo lexicon if you ask me.<br />
4 &#8211; Mind you this was the same guy who left a copy of a magazine on my desk because it had a &#8220;really great&#8221; article about Object COBOL.  He never managed to switch us from C/C++ to that thank God.<br />
5 &#8211; Apparently it’s <a href="http://www.lunch20.com/about/" target="_blank">&#8220;The lunch as a conversation.&#8221;</a>. Oh dear.<br />
6 &#8211; Released as &#8220;Live Free or Die Hard&#8221; in the States.<br />
7 &#8211; Mind you, I guess we’d be on Blade Runner 2.1 at this stage if that were the case.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/94/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/94/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=94&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/24/wtf-20/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/reflectwtf-20beta.png" medium="image">
			<media:title type="html">WTF 2.0 (beta)</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrofitting Unit Tests Part 3 &#8211; Mock Object Hell</title>
		<link>http://fintanp.wordpress.com/2007/10/23/retrofitting-unit-tests-part-3-mock-object-hell/</link>
		<comments>http://fintanp.wordpress.com/2007/10/23/retrofitting-unit-tests-part-3-mock-object-hell/#comments</comments>
		<pubDate>Tue, 23 Oct 2007 09:39:56 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/23/retrofitting-unit-tests-part-3-mock-object-hell/</guid>
		<description><![CDATA[Picture by greefus groinks Some rights reserved. In the previous part of this series on retrofitting unit tests I talked about how you can break the unit-test as integration-test pattern by introducing mock objects. Probably the best way to do this is by using one of the many mock object toolkits out there1 . For [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=88&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table class="image" align="left" width="180">
<tr>
<td><img src="http://fintanp.files.wordpress.com/2007/10/banged-up-spoiler.jpg?w=180" alt="Spoiler worth more than car" style="border:medium none;" width="180" /></td>
</tr>
<tr>
<td class="caption"><font color="gray" size="-2">Picture by <a href="http://www.flickr.com/photos/stinkypeter/" target="_blank">greefus groinks</a><br />
<a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank"><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif?w=500" alt="Attribution" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif?w=500" alt="Share Alike" align="middle" /></a><a href="http://creativecommons.org/licenses/by-sa/2.0/deed.en-us" target="_blank">Some rights reserved.</a></font></td>
</tr>
</table>
<p>In the <a href="http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/">previous part</a> of this series on retrofitting unit tests I talked about how you can break the unit-test as integration-test pattern by introducing <a href="http://en.wikipedia.org/wiki/Mock_object" target="_blank">mock objects</a>.  Probably the best way to do this is by using one of the many mock object toolkits out there<sup>1</sup> .  For Java development my preference is for <a href="http://www.easymock.org/" target="_blank">EasyMock</a> although there are plenty of others.</p>
<p>Introducing mock objects can cause their own set of headaches though and when retrofitting unit tests to existing code you’re likely to find a number of reasons why it can prove difficult or even impossible to introduce them.</p>
<p><span id="more-88"></span>The first and often hardest problem to get around is that the code to be tested is tightly-coupled with the dependency you’re trying to mock out.  If class A uses an instance of class B it’ll be impossible to mock that instance if it’s constructed somewhere inside class A.  You can get around this by doing a small amount of refactoring and introducing dependency injection but there could be the suspicion that you’re changing the design of your code to make it testable.</p>
<p>I really like dependency injection and inversion of control as general patterns but I realise that it’s something of a controversial subject.  The arguments for and against it are summed up well in <a href="http://martinfowler.com/articles/injection.html" target="_blank">Martin Fowler’s excellent piece</a> on the subject and there’s been an ongoing discussion on <a href="http://www.mockobjects.com" target="_blank">mockobjects.com</a> about it’s use in unit testing as well.  Some of the people I’ve spoken to who dislike DI feel that it breaks basic rules of encapsulation.  Personally I think you need to strike a balance between encapsulation and tight-coupling between objects.</p>
<p>Assuming you’re coding to interfaces I see no reason why you can’t inject the implementation to be used without breaking encapsulation.  If anything you’ll just be exposing your object’s contract with the rest of the system rather than how it works.  To add a bit of DI while avoiding having to change the way the object is used throughout the code you could add a package-scope constructor that sets the mock instance required.  By making it package-scope you&#8217;re limiting the scope for it to be used outside of the context of a unit test.  The drawback is that you&#8217;re now adding code purely for testing and your test will be bypassing the constructor used at runtime.</p>
<p>One alternative solution to dependency injection when you need to break tightly-coupled dependencies in unit tests is to use <a href="http://en.wikipedia.org/wiki/Aspect_oriented_programming" target="_blank">Aspects</a>.  You could create an Aspect to intercept invocations on particular methods, creating a kind of pseudo-mock. <a href="http://www.xprogramming.com/xpmag/virtualMockObjects.htm" target="_blank">This article</a> on <a href="http://www.xprogramming.com" target="_blank">xprogramming.com</a> has a good description of an implementation of mock objects using aspects. This isn’t something I’ve had a chance to try out but I suspect it has some drawbacks and any implementation may prove complex. If you try it out let me know how you get on.</p>
<p>Apart from tight-coupling between objects there are other problems you’ll come across when introducing mock objects while retrofitting unit tests in Java code.  Static and final methods are the enemy of mock objects as are public properties, particularly with something like EasyMock.  Statics and finals can’t be overridden and the mock object will have no control over access to public properties. If there are a lot of these in the code to be tested then it can cause problems for your mock objects.</p>
<p>Sometimes though these problems are code-smells and deserve to be refactored as you go.  Public properties are the antithesis of encapsulation and direct access should be replaced with the use of getter and setter methods<sup>2</sup>.  Statics often indicate a laziness or poor understanding of object-oriented design while a lot of finals can often be a sign of <a href="http://fintanp.wordpress.com/2007/03/15/premature-optimization/" target="_blank">premature optimisation</a>.</p>
<p>You can get around some of these problems with a slight refactoring of the code under test.  Refactoring as you go is part of the basic approach to writing a unit test anyway but when you’re working on existing code you need to do it carefully, especially if you have a limited understanding of what the code is doing in the first place.  Your best bet is to write as much of the test as you can, refactor the code a little and write more of the test.  Run the test each time you change something to make sure that you’re at least keeping the result of your test consistent with the previous result.</p>
<p>Finally, mock objects are great but not if you have to mock a complex data model.  Remember that the purpose of a mock object is to model the behaviour of some external dependency without having it actually do anything.  If you find that you’re creating mock object after mock object to model a set of beans you’re heading in the wrong direction.  If a complex data model is required you’re better off having a test data model handy that can be dropped into the code under test, perhaps as the return value from a call to an object that is mocking the model’s container.  Again there might be a code smell here if an object is essentially a container for some data but has a method that performs some transformation or operation on that data.  There may be a case of divided responsibilities and a need to split the class in two.</p>
<p>In the next part of the series I’ll talk about how to react when, having broken your dependencies using mock objects, your new unit test looks hideously complex.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; Why re-invent the wheel?<br />
2 &#8211; God help you if you’re opposed to DI on encapsulation grounds but are quite happy to expose class properties publicly.  You&#8217;ll deserve everything you get&#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/88/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/88/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=88&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/23/retrofitting-unit-tests-part-3-mock-object-hell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/banged-up-spoiler.jpg" medium="image">
			<media:title type="html">Spoiler worth more than car</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif" medium="image">
			<media:title type="html">Attribution</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif" medium="image">
			<media:title type="html">Share Alike</media:title>
		</media:content>
	</item>
		<item>
		<title>Rigging the Irish Election? I Have A Better Idea.</title>
		<link>http://fintanp.wordpress.com/2007/10/20/rigging-the-irish-election-i-have-a-better-idea/</link>
		<comments>http://fintanp.wordpress.com/2007/10/20/rigging-the-irish-election-i-have-a-better-idea/#comments</comments>
		<pubDate>Sat, 20 Oct 2007 10:49:05 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Humour]]></category>
		<category><![CDATA[Politics]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/20/rigging-the-irish-election-i-have-a-better-idea/</guid>
		<description><![CDATA[Picture by scamall Some rights reserved. Damien Mulley has a series of posts about how to rig the Irish election and it all sounds like a fierce hard amount of work to me. I have a much simpler idea about how you might influence the outcome of a general election in Ireland1. 1. Make sure [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=86&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table class="image" align="left" width="120">
<tr>
<td><img width="120" src="http://fintanp.files.wordpress.com/2007/10/vote-tayto.jpg?w=120" alt="Couldn't be worse than half the rubbish in the Dail" style="border:medium none;" /></td>
</tr>
<tr>
<td class="caption"><font color="gray" size="-2">Picture by <a href="http://flickr.com/photos/66265788@N00/" target="_blank">scamall</a><br />
<a href="http://creativecommons.org/licenses/by-nc-nd/2.0/" target="_blank"><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif?w=500" alt="Attribution" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_noncomm_small.gif?w=500" alt="Non-Commercial" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_noderivs_small.gif?w=500" alt="No derivative works" align="middle" /></a><br /><a href="http://creativecommons.org/licenses/by-nc-nd/2.0/deed.en-us" target="_blank">Some rights reserved.</a></font></td>
</tr>
</table>
<p>Damien Mulley has <a href="http://www.mulley.net/2007/10/15/rigging-the-irish-election-part-1-create-cells-of-organisers/" target="_blank">a series of posts</a> about how to rig the Irish election and it all sounds like a fierce hard amount of work to me.  I have a much simpler idea about how you might influence the outcome of a general election in Ireland<sup>1</sup>.</p>
<p>1. Make sure your political party has a well organised grass-roots movement like, say, <a href="http://www.fiannafail.ie/" target="_blank">this one does</a>.</p>
<p>2. Make <a href="http://www.rte.ie/news/2004/0223/evoting.html" target="_blank">excuses</a> and some lame attempts to <a href="http://www.rte.ie/news/2007/0425/voting.html" target="_blank">embarrass the public</a> into accepting e-Voting machines, solving a problem that doesn&#8217;t exist<sup>2</sup>.  You could try <a href="http://www.election-systems.eu/website/Read.php?PageID=1090&amp;chooser_language_id=2" target="_blank">these ones</a>. I think we already have <a href="http://www.rte.ie/news/2006/0323/evoting.html" target="_blank">some in stock</a>.</p>
<p><span id="more-86"></span>3. Call the election for a weekday rather than a weekend <a href="http://www.rte.ie/news/2007/0322/ahernb.html" target="_blank">for the convenience of voters.</a><sup>3</sup></p>
<p>4. Use the aforementioned grass-roots movement, and perhaps <a href="http://www.thepost.ie/post/text/story.asp?document_id=26470&amp;category_name=PROFILE" target="_blank">some friendly mini-bus owners</a>, to bus voters to the polling places early to form long lines out the door.</p>
<p>5. Encourage these early voters, <a href="http://www.indymedia.ie/article/76809" target="_blank">especially the loyal elderly ones</a>, to become &#8220;confused&#8221; and take their time in figuring out who to vote for.  So many candidates&#8230;. What button do I press again? This will delay voters for other parties who may, in their frustration, <a href="http://arstechnica.com/news.ars/post/20070424-afrench-e-voting-catastrophe.html" target="_blank">just go home without voting</a>.</p>
<p>6. Announce the results at 3am in a PowerPoint presentation and quietly mention the fact that although there&#8217;s no paper trail the result can be trusted because computers <a href="http://www.theregister.co.uk/2007/09/03/scotland_votes/" target="_blank">never lose votes</a>. The turnout may be low (see previous point) but at least the majority voted for your party.</p>
<p>As a backup plan try to figure out some way of hacking the secure e-Voting machines.  You could always use <a href="http://www.wijvertrouwenstemcomputersniet.nl/other/es3b-en.pdf" target="_blank">this document</a> as a starting point.</p>
<p>Okay so it&#8217;s hardly a realistic scenario but like Damien I&#8217;m being satirical&#8230;</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; Without having to resort to <a href="http://archives.tcm.ie/businesspost/2007/03/25/story22132.asp" target="_blank">expensive vote buying tactics</a> of course.<br />
2 &#8211; Except how to make money for the company that produces the voting machines.<br />
3 &#8211; Apart from students and people who are forced to commute great distances to work in Dublin from their homes in Portlaoise, Athlone, Mullingar&#8230;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/86/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/86/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=86&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/20/rigging-the-irish-election-i-have-a-better-idea/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/vote-tayto.jpg" medium="image">
			<media:title type="html">Couldn't be worse than half the rubbish in the Dail</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif" medium="image">
			<media:title type="html">Attribution</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_noncomm_small.gif" medium="image">
			<media:title type="html">Non-Commercial</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_noderivs_small.gif" medium="image">
			<media:title type="html">No derivative works</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrofitting Unit Tests Part 2 &#8211; When A Unit Test Isn&#8217;t</title>
		<link>http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/</link>
		<comments>http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 12:17:28 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/</guid>
		<description><![CDATA[Picture by icathing Some rights reserved. One of the most common mistakes I’ve found, particularly with teams who haven’t had a good deal of experience of unit testing or TDD, is that if they do have unit tests they&#8217;re often really integration tests with fake mustaches. A small, relatively self-contained piece of code needs a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=84&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table class="image" align="left" width="180">
<tr>
<td><img width="180" src="http://fintanp.files.wordpress.com/2007/10/chick-magnet.jpg?w=180" alt="Spoiler Carpentry" style="border:medium none;" /></td>
</tr>
<tr>
<td class="caption"><font color="gray" size="-2">Picture by <a href="http://www.flickr.com/photos/icathing/" target="_blank">icathing</a><br />
<a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank"><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif?w=500" alt="Attribution" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif?w=500" alt="Share Alike" align="middle" /></a><a href="http://creativecommons.org/licenses/by-sa/2.0/deed.en-us" target="_blank">Some rights reserved.</a></font></td>
</tr>
</table>
<p>One of the most common mistakes I’ve found, particularly with teams who haven’t had a good deal of experience of unit testing or TDD, is that if they do have unit tests they&#8217;re often really integration tests with fake mustaches.  A small, relatively self-contained piece of code needs a database with test data or a running ORB and server process otherwise the test &#8220;fails&#8221;.</p>
<p>The issue here is one of scope and the key word is “unit”.  Typically this is a single class but could even be a single method in a class. A unit test should only test a single unit of code and not any of its external dependencies. If you’re writing a test to see if a particular Java class aggregates some data correctly prior to writing it to a database then you shouldn’t need a database to find out if it works or not.  The test ends when the database is invoked with the correct (or incorrect!) data and the database is treated like a black box that just works.</p>
<p><span id="more-84"></span>The reasons for this are quite simple. If you are relying on a database and the test fails you’ll have no idea if it failed because of some problem in the code or in the database.  You should be able to work this out, perhaps with a little digging, but false positives like this waste time and seriously reduce your confidence in the ability of unit tests to perform decent regression testing.  Imagine having a test that ran in the past but now fails after you make a change to the code being tested.  You have to figure out did it fail because of something you did or because the external dependency (e.g. the database) is broken or isn&#8217;t set up properly?</p>
<p>Another good reason is that your unit tests should run quickly. If it takes a long time to run all your tests as part of your build the inclination will be to avoid running them. Reducing the amount of execution time spent outside the code under test will help keep them quick. With Java projects I prefer to have the default Ant build target run my unit tests and have a separate &#8220;quick&#8221; build target to build without the tests. Apart from anything else it makes sure that I don&#8217;t forget to run my unit tests while I&#8217;m making changes and before I check any of those changes into source control.</p>
<p>Integration tests are important and if you have some masquerading as unit tests don’t bin them.  You can do one of two things:</p>
<ul>
<li>
Move them to a separate area and run them using a different test regime<sup>1</sup>.  Your unit tests have come out of the closet and are now proud integration tests.  Now go off and write unit tests to replace them, being careful to avoid dragging in the external dependencies.
</li>
<li>
Alternatively change the existing tests to decouple your external dependencies so that they don’t rely on them being in place to work. Drop the orb and the database and mock them.
</li>
</ul>
<p>Either way mock objects can be incredibly useful and I use them extensively in my tests. If you don’t know what mock objects are have a read of <a href="http://martinfowler.com/articles/mocksArentStubs.html">this great article by Martin Fowler</a> and some of the more meaty posts on <a href="http://www.mockobjects.org/">the Mock Objects blog</a>.  The basic idea is that you create a dummy version of the external component, set an expectation of how it should be used and behave but without it actually having to do any real work.</p>
<p>Treating external dependencies as black boxes like this is okay.  Imagine you have a class A which uses class B and you have a passing unit test for class B.  You can test class A with a mock class B and, if the test passes, can be highly confident that when you put A with a real B it&#8217;ll work.  On top of that your unit test for class A will run quicker and be less brittle.</p>
<p>In the next part of this series I&#8217;ll talk a bit more about mock objects and the problems with introducing them when retrofitting unit tests.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; There is a school of thought that Continuous Integration should be a continuous run of your integration tests but that’s a whole different argument to be had.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/84/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/84/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=84&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/19/retrofitting-unit-tests-part-2-when-a-unit-test-isnt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/chick-magnet.jpg" medium="image">
			<media:title type="html">Spoiler Carpentry</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif" medium="image">
			<media:title type="html">Attribution</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif" medium="image">
			<media:title type="html">Share Alike</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrofitting Unit Tests</title>
		<link>http://fintanp.wordpress.com/2007/10/18/retrofitting-unit-tests/</link>
		<comments>http://fintanp.wordpress.com/2007/10/18/retrofitting-unit-tests/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 22:16:05 +0000</pubDate>
		<dc:creator>fintanp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://fintanp.wordpress.com/2007/10/18/retrofitting-unit-tests/</guid>
		<description><![CDATA[Picture by hugovk Some rights reserved. A while ago I promised to write a few articles on the art of test-driven development or TDD1. Rather than starting with TDD itself I wanted to start by talking about what happens when you try to write unit tests after you write your code. This can happen for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=72&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table class="image" align="left" width="180">
<tr>
<td><img width="180" src="http://fintanp.files.wordpress.com/2007/10/speedy-red-car-cropped.jpg?w=180" alt="Speedy Red Car" style="border:medium none;" /></td>
</tr>
<tr>
<td class="caption"><font color="gray" size="-2">Picture by <a href="http://www.flickr.com/photos/hugovk/" target="_blank">hugovk</a><br />
<a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank"><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif?w=500" alt="Attribution" align="middle" /><img src="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif?w=500" alt="Share Alike" align="middle" /></a><a href="http://creativecommons.org/licenses/by-sa/2.0/deed.en-us" target="_blank">Some rights reserved.</a></font></td>
</tr>
</table>
<p>A while ago I promised to write a few articles on the art of test-driven development or <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a><sup>1</sup>. Rather than starting with TDD itself I wanted to start by talking about what happens when you try to write unit tests <em>after</em> you write your code.</p>
<p>This can happen for any number of reasons. A team may want a suite of unit tests with good coverage but may not be willing or experienced enough to either try TDD or make it work. All too frequently a team that isn&#8217;t used to writing unit tests, or can&#8217;t get it&#8217;s collective head around how you can write a test for something that doesn&#8217;t exist yet, will usually revert to writing the test afterwards. The result is that unit tests drop down on the priority list and are the first thing to be cut when a project starts slipping.</p>
<p><span id="more-72"></span>This isn’t helped by the fact that the very word “test” implies something done after the fact<sup>2</sup>. I’ve lost track of the number of interviews or conversations I’ve had where, when TDD comes up, I get a knowing look and the question “Did you really write your tests first?” as if it was okay, I was with friends and could admit that I just dive straight in and write the code first. No, I like to write my unit tests first. That’s why it’s called test-<em>driven</em> development.</p>
<p>As I’ve moved around in a couple of different jobs recently though I&#8217;ve found myself working on code with few<sup>3</sup> unit tests. As a result I’ve picked up a lot of experience in retrofitting unit-tests to existing code. Over the next few weeks I&#8217;ll be sharing some of the experiences I&#8217;ve had and how I solved some of the problems that came up.</p>
<p>First up: when a unit test isn&#8217;t.</p>
<p>&#8211; Fintan</p>
<hr />1 &#8211; And then proceeded to write nothing at all for the next few months&#8230;<br />
2 &#8211; Behaviour-Driven Development aims to fix this but more about that in a later article.<br />
3 &#8211; If any.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fintanp.wordpress.com/72/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fintanp.wordpress.com/72/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fintanp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fintanp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fintanp.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fintanp.wordpress.com&amp;blog=112271&amp;post=72&amp;subd=fintanp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fintanp.wordpress.com/2007/10/18/retrofitting-unit-tests/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fefd4a9c0730bf11295b7f5bc1f685d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fintanp</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/10/speedy-red-car-cropped.jpg" medium="image">
			<media:title type="html">Speedy Red Car</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_attribution_small.gif" medium="image">
			<media:title type="html">Attribution</media:title>
		</media:content>

		<media:content url="http://fintanp.files.wordpress.com/2007/04/cc_icon_sharealike_small.gif" medium="image">
			<media:title type="html">Share Alike</media:title>
		</media:content>
	</item>
	</channel>
</rss>
