<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>graemef.com</title>
	
	<link>http://graemef.com</link>
	<description>A collection of *really long* tweets by GraemeF</description>
	<lastBuildDate>Tue, 16 Feb 2010 19:14:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/graemefdotcom" /><feedburner:info uri="graemefdotcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Don’t jump the red light!</title>
		<link>http://feedproxy.google.com/~r/graemefdotcom/~3/YJlQhJubYzk/</link>
		<comments>http://graemef.com/2010/02/dont-jump-the-red-light/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 20:29:29 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[caliburn]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://graemef.com/?p=8</guid>
		<description><![CDATA[There’s a good reason why the test-driven development cycle says you should always watch a test fail before you write the production code that makes it pass. I was taught a lesson in this today, “school of hard knocks” style… How did it happen? I have a simple class which implements INotifyPropertyChanged and has property: [...]]]></description>
			<content:encoded><![CDATA[<p>There’s a good reason why the <a href="http://en.wikipedia.org/wiki/Test-driven_development">test-driven development cycle</a> says you should always watch a test fail before you write the production code that makes it pass. I was taught a lesson in this today, “school of hard knocks” style…</p>
<h3>How did it happen?</h3>
<p>I have a simple class which implements <code>INotifyPropertyChanged</code> and has property:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:2b42539b-17a3-4a0a-81db-1541402bf746" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush:c#">public class MyClass : INotifyPropertyChanged
{
    private string _name;

    public string Name
    {
        get { return _name; }
        set
        {
            _name = value;
            PropertyChanged(this, new PropertyChangedEventArgs("Name"));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
}</pre>
</div>
<p>To test that the PropertyChanged event is raised at the appropriate time I use <a href="http://www.codeplex.com/caliburn">Caliburn</a>’s handy (and very readable) <code>PropertyHasChangedAssertion</code>:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:36a21e93-ec1a-488c-b821-a2ab147b401d" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush:c#">[TestFixture]
public class MyClassTestFixture
{
    [Test]
    public void Name_WhenSet_RaisesPropertyChanged()
    {
        var test = new MyClass();

        test.AssertThatChangeNotificationIsRaisedBy(x =&gt; x.Name);
    }
}</pre>
</div>
<p>At the time I obviously thought this was too simple to worry about, saw the test passed as expected and moved on. All good… Or so it seemed!</p>
<p>Fast forward a week or two. I started to get some strange errors – not test failures &#8211; in my MSBuild output:</p>
<blockquote><p><code>error : Internal error: An unhandled exception occurred.</code></p>
<p><code> </code><code>error : System.Exception: No context was provided to test the notification, use When(Action affectProperty) to provide a context. </code></p>
<p><code> </code><code>error :    at Caliburn.Testability.Assertions.PropertyHasChangedAssertion`2.Finalize()</code></p></blockquote>
<p>Not only is the message a bit cryptic without any context (e.g. a test) but the error was intermittent. Oh joy! After a bit of detective work (more than you might think!) I realised that this is because the Caliburn’s <code>PropertyHasChangedAssertion</code> checks that you called its <code>When(Action affectProperty)</code> method in its finalizer:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:28cae41e-8235-4729-835b-7c9c7428c806" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush:c#">~PropertyHasChangedAssertion()
{
    if(!_isValidAssertion)
        throw new Exception(
            "No context was provided to test the notification, use When(Action affectProperty) to provide a context.");
}</pre>
</div>
<p>While this makes the test extremely readable (which is, of course, extremely important), if you forget to call <code>When()</code>, if and when you get an error is up to the non-deterministic finalization gods. An easy one to fix:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:3f633c3b-4a0e-4572-9d24-5e94fa3ecbd8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush:c#">[Test]
public void Name_WhenSet_RaisesPropertyChanged()
{
    var test = new MyClass();

    test.AssertThatChangeNotificationIsRaisedBy(x =&gt; x.Name)
        .When(() =&gt; test.Name = "New name");
}</pre>
</div>
<p>But I didn’t get the feedback that I should have done from doing TDD properly, and wasted time as a result.</p>
<h3>What went wrong?</h3>
<p>Here is how TDD is <em>supposed</em> to be performed:</p>
<p><a title="Test-driven_development" href="http://flickr.com/photos/9300692@N02/3987593006"><img src="http://farm3.static.flickr.com/2627/3987593006_35c4195cab.jpg" alt="" /></a></p>
<p>Because the code was trivial, I skipped the second step and didn’t check that the test failed before I carried on and implemented the property. If I hadn’t skipped this step, there’s a good chance that the following sequence of events would have occurred:</p>
<ol>
<li><span style="background-color: #ffffff;">I write the test, and add an empty property definition to make it compile</span></li>
<li><span style="background-color: #ffffff;">I run the test and <em>see that it unexpectedly passes</em></span></li>
<li><span style="background-color: #ffffff;">I scratch my head for a bit, but I’m already looking at the offending line of code so it’s much easier to spot the problem</span></li>
<li><span style="background-color: #ffffff;">The penny drops, I spot the mistake and fix it</span></li>
<li><span style="background-color: #ffffff;">I run the test again, and this time it fails. Happy days.</span></li>
<li><span style="background-color: #ffffff;">I implement the property changed notification and carry on</span></li>
</ol>
<p>Maybe I would have got the error when I ran the test, and that would have given me another clue about the cause of the problem.</p>
<h3>It could have been worse!</h3>
<p>In the week or two since I made the mistake I could have carried on to use <code>AssertThatChangeNotificationIsRaisedBy</code> in tens or hundreds of other tests, which would have made it much harder to find the one with the missing <code>When()</code> call. I was lucky that there were only a few uses in my tests.</p>
<h3>A lesson learned?</h3>
<p>I hope so! When time is short it can be hard to make yourself go through these steps over and over again, but they are all there for a reason – <em>to stop us writing code that doesn’t do what we think it does</em>. I will be trying especially hard to stick to the steps, but we’ll have to wait and see how it goes.</p>
]]></content:encoded>
			<wfw:commentRss>http://graemef.com/2010/02/dont-jump-the-red-light/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://graemef.com/2010/02/dont-jump-the-red-light/</feedburner:origLink></item>
		<item>
		<title>How I’m Growing Object-Oriented Software, Guided by Tests</title>
		<link>http://feedproxy.google.com/~r/graemefdotcom/~3/JyhrDbkHRuk/</link>
		<comments>http://graemef.com/2010/02/how-im-growing-object-oriented-software-guided-by-tests/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 20:22:53 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[goos]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://graemef.com/?p=6</guid>
		<description><![CDATA[Growing Object-Oriented Software, Guided by Tests (that&#8217;s #goos on Twitter) by Steve Freeman and Nat Pryce is a book about test-driven development. Here are a few notes on my experiences of following its methods. The Story So Far I was fortunate enough to start work on a new desktop application in the middle of last [...]]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://rcm-uk.amazon.co.uk/e/cm?t=graemefcom-21&#038;o=2&#038;p=8&#038;l=as1&#038;asins=0321503627&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="right"></iframe><br />
<a href="http://www.growing-object-oriented-software.com/">Growing Object-Oriented Software, Guided by Tests</a> (that&#8217;s <a href="http://twitter.com/#search?q=%23goos">#goos</a> on Twitter) by <a href="http://www.m3p.co.uk/">Steve Freeman</a> and <a href="http://www.natpryce.com/">Nat Pryce</a> is a book about test-driven development. Here are a few notes on my experiences of following its methods.</p>
<h3>The Story So Far</h3>
<p>I was fortunate enough to start work on a new desktop application in the middle of last year, around the time I read through the freely-available online version of the book before it was finally published in November. This was an ideal opportunity to put TDD into practice so I started by building a “walking skeleton” using <a href="http://www.codeplex.com/CompositeWPF">Prism</a>, <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET">CruiseControl.NET</a>, <a href="http://wix.sourceforge.net/">WiX</a>, <a href="http://www.gallio.org/">Gallio</a>, <a href="http://www.mbunit.com/">MbUnit</a>, <a href="http://www.ncover.com/">NCover</a> and <a href="http://white.codeplex.com/">White</a> as a wrapper around <a href="http://msdn.microsoft.com/en-us/library/ms747327.aspx">UI Automation</a> for the acceptance tests, and took it from there.</p>
<p>I’ll admit that there was a slow start (WPF/Prism and White/UI Automation were new to me too) but development speed has been steadily increasing ever since, and now I’m able to get what feels like a lot done each day. And that’s pretty much <em>every</em> day; it’s been a long time since I’ve had to halt progress for a significant amount of time in order to squash a bug or redo a chunk of work.</p>
<h3>Where am I now?</h3>
<p>I’m still learning. It’s easy to slip back into changing code then updating the tests to match, and I do find myself doing that sometimes. I’m also finding it hard to perform only one refactoring step at a time (oh, let me just rename that class while I’m here…), and the acceptance tests can be brittle and sometimes feel like a burden to write. But what doesn’t kill you makes you stronger, right? It’s getting noticeably easier as I learn and improve, and every bit of pain along the way has been worth it.</p>
<h3>Does it work?</h3>
<p>For me, <strong>yes</strong>. Test-driven development feels <em>so right </em>that I don’t think I could ever go back to hacking stuff together without building the safety net of tests to fall back on as I go. I am sure that my design is much better than anything I have produced before, and that I have far fewer bugs than usual, too <img src='http://graemef.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So this experience has been nothing short of (professional) life-changing. I have read similar stuff before, but <em>GOOS</em> was the one that finally made me “get it.”</p>
]]></content:encoded>
			<wfw:commentRss>http://graemef.com/2010/02/how-im-growing-object-oriented-software-guided-by-tests/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://graemef.com/2010/02/how-im-growing-object-oriented-software-guided-by-tests/</feedburner:origLink></item>
		<item>
		<title>Hello again, World!</title>
		<link>http://feedproxy.google.com/~r/graemefdotcom/~3/2aOfZPSj3D4/</link>
		<comments>http://graemef.com/2010/02/hello-again-world/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 16:39:29 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
				<category><![CDATA[meta]]></category>

		<guid isPermaLink="false">http://graemef.com/?p=4</guid>
		<description><![CDATA[Hello Sand message from Crestock Creative Photos GraemeF.com has been around in one form or another since 2001, but I had a poke around the blog content and decided that each bit fell into one or more of the following categories: Outdated technical posts that would be downright misleading now; Personal stuff that the Interwebs [...]]]></description>
			<content:encoded><![CDATA[<div class="crestock-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 410px;">
<dt class="wp-caption-dt"><img title="Hello written in beautiful white sand" src="/wp-content/uploads/crestockimages/1262735-ms.jpg" alt="Hello written in beautiful white sand" /></dt>
<dd class="wp-caption-dd crestock-img-attribution" style="font-size: 0.8em;"><a href="http://www.crestock.com/image/1262735-Hello-Sand-message.aspx">Hello Sand message</a> from <a href="http://www.crestock.com/free-image.aspx">Crestock Creative Photos</a></dd>
</dl>
</div>
</div>
<p><em>GraemeF.com</em> has been around in one form or another since 2001, but I had a poke around the blog content and decided that each bit fell into one or more of the following categories:</p>
<ol>
<li>Outdated technical posts that would be downright misleading now;</li>
<li>Personal stuff that the Interwebs should not be interested in;</li>
<li>Links auto-posted from <a href="http://delicious.com/GraemeF">my Del.icio.us account</a>;</li>
<li>Factually inaccurate bullshit.</li>
</ol>
<p>So, rather than actually create categories for the above, I decided to reboot my blog, and now all of the old content is gone.</p>
<h3>So what now?</h3>
<p>It’s time for a fresh start. Having dabbled with product management for a while and ultimately decided that it’s not for me, I’m back to being a full-time software developer, and that’s what I intend to write about.</p>
<p>However, what’s more likely to happen is:</p>
<ol>
<li>I start off well, with a couple of posts about test driven development and the like;</li>
<li>The posts get shorter and shorter and are spaced farther and farther apart;</li>
<li>In a year’s time I’ve all but forgotten about it when the hosting charge is applied to my debit card, for which my wife never forgives me.</li>
</ol>
<p>Sounds like a plan! <img src='http://graemef.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://graemef.com/2010/02/hello-again-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://graemef.com/2010/02/hello-again-world/</feedburner:origLink></item>
	</channel>
</rss>
