<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>bdd</title>
        <link>http://geekswithblogs.net/chriscanal/category/7775.aspx</link>
        <description>bdd</description>
        <language>en-GB</language>
        <copyright>Chris Canal</copyright>
        <managingEditor>chris@e4ums.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Test First? Or is that new legacy code you just checked in?</title>
            <link>http://geekswithblogs.net/chriscanal/archive/2008/05/09/test-first-or-is-that-new-legacy-code-you-just.aspx</link>
            <description>&lt;div style="margin: 5px 20px 20px;"&gt;
&lt;div style="margin-bottom: 2px;" class="smallfont"&gt;Quote:&lt;/div&gt;
&lt;table width="100%" cellspacing="0" cellpadding="6" border="0"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style="border: 1px inset ;" class="alt2"&gt;  ...legacy code is simply code without tests. - &lt;strong&gt;Working Effectivly with Legacy Code - Micheal Feathers&lt;/strong&gt; &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
I was discussing testing with a friend the other day, mainly Test Driven Development and we got onto the topic of new code without tests and retrofitting them. The first thing that popped into my head was the above quote and the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin: 5px 20px 20px;"&gt;
&lt;div style="margin-bottom: 2px;" class="smallfont"&gt;Quote:&lt;/div&gt;
&lt;table width="100%" cellspacing="0" cellpadding="6" border="0"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style="border: 1px inset ;" class="alt2"&gt; Code without tests us bad code. It doesn't matter how well written it is; it doesn't matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behaviour of our code quickly and verifiably. Without them, we really don't know if our code is getting better or worse. &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
You can imagine his reaction after I shared this with him.&lt;br /&gt;
&lt;br /&gt;
However, I completely agree with that Micheal is saying. Any code without tests, no matter if it was written a few hours ago or a year, is bad legacy tests. Retrofitting tests on the code then becomes a task with dealing with &lt;em&gt;legacy code&lt;/em&gt;. True, you will probably not have as hard a time dealing with new legacy than you would older legacy code, but the main issue is that your still dealing with legacy code.&lt;br /&gt;
&lt;br /&gt;
Once the code is written, retrofitting tests isn't Test Driven Development. Your not designing the code to make your tests pass, your designing you tests to ensure behaviour of exisiting code, and this means &lt;em&gt;legacy code&lt;/em&gt;. Would I recommend retrofitting tests? No, I would give it a miss, concentrate more on integration testing. Add unit tests on the code when your editing it, as you would with, you guessed it, legacy code.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;My Code isn't bad because it doesn't have tests!&lt;/strong&gt;&lt;br /&gt;
It was never my intetion to insult friend, but the fact still remains that I agree with the above quote and view any code without tests as bad code. The key aspect of a good application is not how cool the code or how slick he UI is, but how maintainable it is. And not maintainable for you, but the developer after you.&lt;br /&gt;
&lt;br /&gt;
Over the years I've worked on some really nice applications. The UI is nicely design, the customers are happy with how everything works, but without tests, maintaining it is magnatidues more difficult than an application that does.&lt;br /&gt;
&lt;br /&gt;
How can a new developer to an applicaton confidently make changes if there is nothing to verify the changes? Sure, they can sit and manually test the UI is doing as it should, but what about the subtle bugs that can be introduced? The side affects of a change that can appear somewhere else in the application. I've experienced nasty side-affects without tests before, and when they are in an unrelated section of the code, it can be a nightmare without to track down.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Un-legacying your code&lt;br /&gt;
&lt;/strong&gt;As I said before, there isn't much point in retro-fitting tests as an actual task. Concentrate on adding tests whenever your going to be working on an area. The goal is to introduce confidence building tests and either maintain behaviour when refactoing, or ensuring you don't break anything when changing behaviour.&lt;br /&gt;
&lt;br /&gt;
Without TDD, your probably going going to have to break dependencies. The one common issue I've come across when helping people deal with legacy code is dependencies and interaction with the database. if your test hits an external resoruce, then its not a unit test. A unit test should be small, quick to run, atomic and run is isolation. This makes it difficult to add tests to code that uses things like LINQ to SQL as they are very tightly coupled to the database, trying getting a test quickly and easily in a test harness. Anything that ties your application to a data source is not a good option for maintanability.&lt;br /&gt;
&lt;br /&gt;
It's also detrimental to running the tests. Having tests that hits the database can be time consuming, time consuming tests == test that will probably not be ran and then your back to writing legacy code.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Errr... the point?&lt;/strong&gt;&lt;br /&gt;
So, the point? Well, learn TDD. I know I do keep going on about this, but I do have a good reason. TDD is new to .NET, it needs more people to take it up. Microsoft has just started with the MVC Framework, so momentum is growing. But it's the troops out in the field that need to pick it up too. Trust me, when you get into the full swing of it coding is &lt;em&gt;&lt;strong&gt;exteremly&lt;/strong&gt;&lt;/em&gt; fun again, even the boring tweaks. You've always got a safety net so huge refactoring or changes hold no fear, late requirements from a client are no longer a reason to moan or a worry.&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122014"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122014" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/chriscanal/aggbug/122014.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Canal</dc:creator>
            <guid>http://geekswithblogs.net/chriscanal/archive/2008/05/09/test-first-or-is-that-new-legacy-code-you-just.aspx</guid>
            <pubDate>Fri, 09 May 2008 14:33:54 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/chriscanal/comments/122014.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/chriscanal/archive/2008/05/09/test-first-or-is-that-new-legacy-code-you-just.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/chriscanal/comments/commentRss/122014.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Handy HttpPostedFile &amp; HttpFileCollection abstractions</title>
            <link>http://geekswithblogs.net/chriscanal/archive/2008/04/23/handy-httppostedfile--httpfilecollection-abstractions.aspx</link>
            <description>&lt;p&gt;I've just upgraded to the latest version interim drop of the MVC framework and MVC Contrib (which I can't seem to build from source using NAnt...).  Everything appeared to be ok, except for one thing: a controller action that uploads a file was now throwing an error: &lt;/p&gt;
&lt;blockquote&gt; cannot convert from 'System.Web.HttpPostedFileBase' to 'System.Web.HttpPostedFile' &lt;/blockquote&gt;
&lt;p&gt;After a few seconds of confusion I quicky dawned on me that this might be a very good thing.  A quick look at the System.Web.Abstractions confirmed my throughts, it now contained abstractions for HttpPostedFile and HttpFileCollection!&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;img width="324" height="446" alt="" src="/images/geekswithblogs_net/chriscanal/images/post_file_reflector.Png" /&gt;&lt;/p&gt;
&lt;p&gt; Color me happy, the only code I couldn't get covered was Actions that handled file uploads.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121589"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121589" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/chriscanal/aggbug/121589.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Canal</dc:creator>
            <guid>http://geekswithblogs.net/chriscanal/archive/2008/04/23/handy-httppostedfile--httpfilecollection-abstractions.aspx</guid>
            <pubDate>Wed, 23 Apr 2008 19:18:43 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/chriscanal/comments/121589.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/chriscanal/archive/2008/04/23/handy-httppostedfile--httpfilecollection-abstractions.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/chriscanal/comments/commentRss/121589.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Resistance to TDD</title>
            <link>http://geekswithblogs.net/chriscanal/archive/2008/03/27/resistance-to-tdd.aspx</link>
            <description>I've been developing with Test Driven Development for awhile now (more in the form of Behavioural Driven Development) both in and outside of work. I've recently started a new job where TDD isn't used and I've been showing the other developers how I use it.&lt;br /&gt;
&lt;br /&gt;
If you have ever read a TDD book, you'll know every argument against TDD they have given to me:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Adds too much time&lt;/li&gt;
    &lt;li&gt;Not beneficial for the client&lt;/li&gt;
    &lt;li&gt;Makes things complicated&lt;/li&gt;
    &lt;li&gt;It's to be used by people, not machines&lt;/li&gt;
    &lt;li&gt;Bad experience&lt;br /&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;strong&gt;Adds too much time&lt;br /&gt;
&lt;/strong&gt;For me, this smells of a lack of understanding of the TDD process. Granted, I have noticed a slight increase in development time when I shifted to TDD. However, the time added was no where near the time I saved when it come to debugging at the end. In fact, I spend very little time debugging at the end of a project, and when I say little, I'm talking about &lt;strong&gt;very&lt;/strong&gt; little. I don't feel careless or reckless by doing so, the confidence I gain from implementing a comprehensive test suite is unrivaled and I know my code will work exactly as it should.&lt;br /&gt;
&lt;br /&gt;
For me, the natural evolutionary nature of developing with TDD leads me into integration development very early, meaning I also save more time when it comes to implementing the code in a real world situation. Using mocks means I can still keep the tests atomic and isolated. I've recently started using SQL Server CE when I want to test database interaction, so tests can now run without any database setup. And in a Continuous Integration environment this saves so much time it's unbelievable, no one in work will believe me &lt;img border="0" class="inlineimg" title="Wink" alt="" src="file:///C:/Documents%20and%20Settings/User/My%20Documents/Chris/tdd_files/wink.gif" /&gt;&lt;br /&gt;
&lt;br /&gt;
The real time saver though is maintenance. This comes in two forms: lower defect count and being able to locate problems quickly and easily, and being able to work on them in complete isolation.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Not beneficial for the client&lt;br /&gt;
&lt;/strong&gt;I've found it easier to hit very tight deadlines with TDD, and can give far better estimates. And with a lower chance of defects being means less maintenance work from the client and more real paying work. It also gives you the ability to quickly and easily add or change things. I'm talking about &lt;strong&gt;crazy&lt;/strong&gt; quick and easy, especially when using a tool a refactoring tool like Resharper.&lt;br /&gt;
&lt;br /&gt;
These will all lead to clear benefits for the client and the business. You will be able to give better estimates and because TDD will save time and effort, you can deliver a product ahead of time and under budget. The ability to quickly made large changes means you can deliver them to the client quicker and cheaper.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Makes things complicated&lt;br /&gt;
&lt;/strong&gt;Like everything else, there is a learning curve to TDD and when shown the resulting code, my colleagues of insisted it was complicated. I find this argument a little hard to get my head around. I've found my code far easier to understand and work with. I've also found it adhering more to common OO practices. I've found it far easier to see where a pattern could apply, and been able to quickly refactor code to use them. In doing so, I've gained a far better knowledge of patterns and their application.&lt;br /&gt;
&lt;br /&gt;
Yes, I have some fairly complicated tests but that's because I'm aiming for as high as possible code coverage with the least amount of dependencies possible. I do use mocking frameworks, Inversion Of Control containers, but you can still create a comprehensive test suite without making things too complicated. Another argument for this was junior developers working on the code. This I can kind of see the point of, but some mentoring and knowledge share will quickly get the junior developer to a level where they can at least edit tests and add basic ones.&lt;br /&gt;
&lt;br /&gt;
It also raises the question, if the junior developer can't understand the tests and their not willing to learn, should they really be working on the application?&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;It's to be used by people, not machines&lt;br /&gt;
&lt;/strong&gt;I really laughed when I heard this one, it really highlighted a lack of understanding what Test Driven Development is. When I'm trying to explain what TDD is, I sometimes tell them to think of it as Test Driven Design. TDD has more to do with creating clean, well thought out code that testing. Yeah, I've got a lot of confidence in my tests when it comes to testing an application at the current cycle, but TDD is only one layer of testing. It will never replace proper QA testing, and its not aimed to do so.However, I still automated a lot of UI testing. Using WatiN, I write tests aiming to cover all the possibilities and while it's not a person, I've at least got a safety net to rely on whenever any strange UI bugs crop up.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Bad experience&lt;br /&gt;
&lt;/strong&gt;One of the developers has had a fairly bad experience with TDD, but this too still seemed like a poor understanding of TDD, both from the developer and the developers that had implemented TDD. Like everything, what can lead to good practice, can lead to bad or misinformed practice.&lt;br /&gt;
&lt;br /&gt;
But you shouldn't write something off because of one bad experience, it just takes some courage to keep going.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120788"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120788" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/chriscanal/aggbug/120788.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Canal</dc:creator>
            <guid>http://geekswithblogs.net/chriscanal/archive/2008/03/27/resistance-to-tdd.aspx</guid>
            <pubDate>Thu, 27 Mar 2008 11:21:40 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/chriscanal/comments/120788.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/chriscanal/archive/2008/03/27/resistance-to-tdd.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/chriscanal/comments/commentRss/120788.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>