<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Jak Charlton - Insane World : TDD, Testing</title><link>http://devlicio.us/blogs/casey/archive/tags/TDD/Testing/default.aspx</link><description>Tags: TDD, Testing</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Ship it, or Ship Out</title><link>http://devlicio.us/blogs/casey/archive/2009/09/25/ship-it-or-ship-out.aspx</link><pubDate>Fri, 25 Sep 2009 08:38:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:51716</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>27</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=51716</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=51716</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2009/09/25/ship-it-or-ship-out.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.joelonsoftware.com/"&gt;Joel&lt;/a&gt;, in his inimitable way, &lt;a href="http://www.joelonsoftware.com/items/2009/09/23.html"&gt;posted the flame bait of all flame bait posts yesterday&lt;/a&gt;, explaining the role of the Duct Tape Programmer.&lt;/p&gt;
&lt;p&gt;To my surprise, the Twitterverse started to reverberate with commentary, but weirdly, almost all of it was very negative about the post, many claiming that Joel was just creating straw men and knocking them down, or was characterising developers who care about quality as being poor developers.&lt;/p&gt;
&lt;p&gt;I was surprised, because I read the article totally the other way around - and had said so earlier in the day to someone on Twitter, saying I largely agreed with it. It seems that there were two ways of reading the article, and mine differed substantially to most people I follow on Twitter.&lt;/p&gt;
&lt;p&gt;I was quite pleased to see Michael Neel post last night in a &lt;a href="http://devlicio.us/blogs/vinull/archive/2009/09/24/being-a-duct-tape-programmer.aspx"&gt;semi-defence of Joel&amp;#39;s standpoint&lt;/a&gt;, and I thought the 140 char limit of Twitter wasn&amp;#39;t enough for me to post my opinions.&lt;/p&gt;
&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;Joel has a bit of a record on this, he isn&amp;#39;t best liked by a large proportion of the developer community who see their focus and remit as producing high quality, well tested and highly maintainable software. His &lt;a href="http://blog.stackoverflow.com/2009/01/podcast-38/"&gt;original tirades in a podcast&lt;/a&gt; about his deep distrust of Test Driven Development and of Unit Testing in &lt;a href="http://blog.objectmentor.com/articles/2009/01/31/quality-doesnt-matter-that-much-jeff-and-joel"&gt;general brought uproar&lt;/a&gt;. And on that matter he was so far off the mark, it was understandable why he had riled so many people - he really just didn&amp;#39;t understand or &amp;quot;get&amp;quot; TDD or testing in general.&lt;/p&gt;
&lt;p&gt;But, what he had done, in conjunction with &lt;a href="http://www.codinghorror.com/blog/"&gt;Jeff Atwood&lt;/a&gt;, was to deliver a website, &lt;a href="http://stackoverflow.com/"&gt;stackoverflow.com&lt;/a&gt;, that was proving hugely successful, and was being used extensively by all those same developers who railed against his podcasts and blogs.&lt;/p&gt;
&lt;p&gt;That website, as Joel and Jeff explained, was not done with TDD, was not well tested (via Unit Tests), was badly hacked together in places, and used &amp;quot;old&amp;quot; technologies like TSQL over &amp;quot;modern&amp;quot; solutions like ORMs&lt;/p&gt;
&lt;p&gt;Whether Joel &amp;quot;got&amp;quot; TDD wasn&amp;#39;t important, what he and Jeff had done was to ship a product, get it to market, and build upon that release to make stackoverflow the massive success it is today. It&amp;#39;s so successful, that soon after stackoverflow was released, they used the same code and model to release other Q&amp;amp;A sites, and they continue to do so.&lt;/p&gt;
&lt;h3&gt;The Duct Tape Programmer&lt;/h3&gt;
&lt;p&gt;So with all of that in mind, it was sort of obviously flame bait for Joel to make a post that basically boiled down to &amp;quot;shipping it way more important than fancy patterns and great tools&amp;quot; - he certainly has a way of putting such a simple message that can antagonise the meekest of individuals (and some not so meek). &lt;/p&gt;
&lt;p&gt;It was a terrible choice of label, but I guess &amp;quot;Pragmatic Programmer&amp;quot; had already been taken.&lt;/p&gt;
&lt;h3&gt;Time, Quality, Functionality&lt;/h3&gt;
&lt;p&gt;I read the article slight differently - I read it as an urge to maintain your highest priority as shipping the product your business wants you to ship.&lt;/p&gt;
&lt;p&gt;There are three factors involved in a project (if you exclude Resourcing, which falls under Brooks Law):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Time&lt;/li&gt;
&lt;li&gt;Quality&lt;/li&gt;
&lt;li&gt;Functionality (or Scope)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you try and maintain all three factors as fixed, your project is doomed to fail. Something will, unless you are really lucky, break. And then one of those factors will suffer, and it will be luck as to which it is. At best you can fix two of those factors, and then the third has to be allowed to slip when the unexpected happens (as it always does).&lt;/p&gt;
&lt;p&gt;But, the important part here, is that which of those factors is fixed, and which is allowed to slip is NOT a developer decision - it is a business decision.&lt;/p&gt;
&lt;p&gt;Much of the outrage about Joel&amp;#39;s article stated that he isn&amp;#39;t a developer - and they are correct - he is a business owner, and prior to that a project manager. His focus is therefore on shipping his product, and inevitably from that perspective, the instinct is to fix Time and Functionality (ship as soon as possible, with as much functionality as possible) and to let Quality suffer to achieve that objective.&lt;/p&gt;
&lt;p&gt;This is a TOTALLY VALID business decision - it is just one that developers don&amp;#39;t like, it offends their sense of code quality and high standards.&lt;/p&gt;
&lt;h3&gt;Why Do Developers Care So Much About Quality?&lt;/h3&gt;
&lt;p&gt;I&amp;#39;ll start with the cynical view: development is only fun while you are trying new things, trying to perfect a tricky algorithm, or make some great new OSS component do some magic. By nature, the developers who care deeply about quality are also perfectionists, they like to make sure they have done a good job, and have written the best code they can.&lt;/p&gt;
&lt;p&gt;Go on, admit it, if developers just did routine coding all day long, our jobs would be boring. We like new toys, new language features, we like to play.&lt;/p&gt;
&lt;p&gt;And we know that better code will be easier to maintain - and developers HATE bug fixing duty, so we want to ensure we don&amp;#39;t have to do much of it.&lt;/p&gt;
&lt;p&gt;To a developer, the most important factor in any project is Quality, followed by Time (because we know our bosses will be mad if we miss our deadlines), but we are happy to slip Functionality because it matters little to us if a new feature isn&amp;#39;t included in the release.&lt;/p&gt;
&lt;h3&gt;Fundamentally We Are Not Aligned&lt;/h3&gt;
&lt;p&gt;Developers and business owners are not aligned in their goals - we prioritise the three factors very differently, and for different reasons.&lt;/p&gt;
&lt;p&gt;Only two things can happen here, your developers need to align with their business objectives, or the business needs to align with the developers - or they can both compromise.&lt;/p&gt;
&lt;p&gt;Agile is all about the compromise, making both sides aware of the issues involved, and then coming to an agreement, but fundamentally - it is STILL A BUSINESS DECISION.&lt;/p&gt;
&lt;p&gt;While it is the responsibility of a professional developer to explain all the problems they see with low quality code, and to make their boss aware of all the potential future issues this may cause, it is also their professional responsibility to go with the decision their boss makes.&lt;/p&gt;
&lt;p&gt;They have one other option - resign and go somewhere that is more closely aligned with their values.&lt;/p&gt;
&lt;h3&gt;Ship It or Ship Out&lt;/h3&gt;
&lt;p&gt;Whatever your opinions of Joel and Jeff&amp;#39;s understandings of TDD, Unit testing, maintainable code or just code in general (and I&amp;#39;m sure yours aren&amp;#39;t too far from mine), you have to admit they delivered a product to market (many in fact), and have turned it into a huge success. They may have to pay for that speed to market later, but that was a business decision they were willing to take.&lt;/p&gt;
&lt;p&gt;Never underestimate the value to a business of being fast to market - there is a risk the product will be so bugged it will backfire - but there is a chance they could steal the march on their competitors, and gain critical traction. Business is all about assessing risk, that is what a business owner has to do, and if they do it right their business flourishes.&lt;/p&gt;
&lt;p&gt;If your boss wants a product shipped by a particular date, and that is their highest priority, you have a responsibility to ship it. If they won&amp;#39;t sacrifice functionality to achieve that goal, then code quality will have to suffer - in that case do the best you can do with the restraints you are under. And if all that fails, quit, go somewhere that appreciates your values and dedication to your art - you do not have a right to hold your employer to ransom.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So, Ship It or Ship Out.&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=51716" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Rants/default.aspx">Rants</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Twitter/default.aspx">Twitter</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Make It Easy To Refactor</title><link>http://devlicio.us/blogs/casey/archive/2009/09/21/make-it-easy-to-refactor.aspx</link><pubDate>Mon, 21 Sep 2009 15:17:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:51578</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=51578</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=51578</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2009/09/21/make-it-easy-to-refactor.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m currently looking at a code base that could do with some refactoring, overall it&amp;#39;s a pretty good code base, and the test coverage is pretty good too. But looking through it gave me some ideas on what makes a code base tricky to safely refactor. Here are some tips to make sure your code is in a good state to be refactored with safety and confidence.&lt;/p&gt;
&lt;h3&gt;Provide Good Test Names&lt;/h3&gt;
&lt;p&gt;Test methods should have good, meaningful names; this is of course exactly the same as all code - naming is very important to give context and meaning. I am looking at a lot of tests that make sense to the original developer, and within reason make sense to me, but they do not properly describe what the test tries to do and what it expects.&lt;/p&gt;
&lt;p&gt;A test named &amp;quot;ValidHardware()&amp;quot; is less than ideal for telling me the intent of the test.&amp;nbsp; If the method had been correctly named it would have been called:&lt;/p&gt;
&lt;p style="PADDING-LEFT:30px;"&gt;ensure_that_hardware_detector_returns_true_when_valid_hardware_is_present()&lt;/p&gt;
&lt;p&gt;Now you tell me, which is easier to understand? And which is going to give me more confidence in refactoring that hardware detector?&lt;/p&gt;
&lt;h3&gt;Make Sure Variables Are Well Named&lt;/h3&gt;
&lt;p&gt;Probably blindingly obvious given the above section, but if you use poor variable names, I am probably going to waste a lot of time trying to figure out exactly which thing is which, and worse still, I am probably going to miss subtle bugs.&lt;/p&gt;
&lt;h3&gt;Cover The Right Things&lt;/h3&gt;
&lt;p&gt;Beware of high coverage that does not actually test either all the aspects of a component, or that makes a lot of assumptions. &lt;/p&gt;
&lt;p&gt;Getting 100% coverage is likely to be impossible, and probably your return on investment over 75% is going to be low, but don&amp;#39;t achieve the 75% by testing the trivial and easy to test things only - it&amp;#39;s going to be those tricky to test components that will cause most bugs when refactoring.&lt;/p&gt;
&lt;p&gt;If something is tricky to test, perhaps you have the wrong level of abstraction applied, or perhaps the test is trying to tell you something. Skipping it and going for some simpler tests may pay off in the short term, but in the long term will hurt you.&lt;/p&gt;
&lt;h3&gt;Avoid Fragile Tests&lt;/h3&gt;
&lt;p&gt;There is a lot of debate between the &amp;quot;classicist and mockist schools&amp;quot; about what to test, and personally I veer towards state based testing for most components - but regardless of where your personal impulses lie, avoid creating fragile tests. Any test that is likely to break with trivial refactoring could be considered fragile, and those tests are going to cost you a lot of time and cause many potential bugs when refactoring.&lt;/p&gt;
&lt;p&gt;One of the main causes of fragile tests are an overreliance on mocks, and specifically using mocks over stubs. &amp;nbsp;By all means mock where necessary, but try to limit mock usage to very specific test cases, and try to favour stubs over mocks and favour &amp;quot;Setup.ResultFor&amp;quot; over &amp;quot;Expect.Call&amp;quot; type semantics.&lt;/p&gt;
&lt;h3&gt;Avoid [Setup] and [Teardown]&lt;/h3&gt;
&lt;p&gt;Yes, I know they make it easier to create lots of similar tests, but they make your tests fragile and interdependent.&lt;/p&gt;
&lt;p&gt;James Newkirk (who was on the original NUnit team) made a &lt;a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html"&gt;good blog post on this&lt;/a&gt; when he moved to writing xUnit, where Setup and Teardown were removed. &lt;/p&gt;
&lt;p&gt;They make it hard to read your tests (you have to read code in two or three locations to understand what the test does) and can cause Setup/Teardown getting too many responsibilities, leading to fragility or code bloat.&lt;/p&gt;
&lt;p&gt;Either switch to setup within the individual test, or favour a Context based testing approach such as with BDD&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Tests are code, and code has to be maintained too. Make sure your tests are of a similar or higher standard than the rest of your codebase, make sure they test the right things, in the right way, and you will make your life much easier, and that of the guy who comes after you much easier too&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=51578" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Unit+Tests/default.aspx">Unit Tests</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Testing/default.aspx">Testing</category></item></channel></rss>