{"id":551,"date":"2011-07-14T22:05:16","date_gmt":"2011-07-14T22:05:16","guid":{"rendered":"http:\/\/pragmaticcraftsman.kubasek.com\/?p=551"},"modified":"2011-08-02T10:46:35","modified_gmt":"2011-08-02T10:46:35","slug":"joining-the-tdd-camp","status":"publish","type":"post","link":"https:\/\/pragmaticcraftsman.kubasek.com\/?p=551","title":{"rendered":"Joining the TDD camp!"},"content":{"rendered":"<p>I am a TDD fan. I&#8217;ve been one for a long time.<\/p>\n<p>But I&#8217;m not a TDD practitioner. I don&#8217;t follow the TDD methodology of writing the test first, implementation second.<\/p>\n<p>Not yet.<\/p>\n<p>Uncle Bob convinced me to try. Again.<\/p>\n<p>Time to become a TDD developer!\u00a0Time to step up my code quality.<\/p>\n<p>I have said it many times, Robert Martin, Uncle Bob, is someone who has had a big influence on my career (you can find other references on this site). I usually buy all his books. His latest one, The Clean Coder, is not only a joy to read, it&#8217;s filled with great advice. It&#8217;s like reading The Pragmatic Programmers again. Who doesn&#8217;t want that?<\/p>\n<p>Let&#8217;s get to the point, though. Why would I ever want to follow TDD? Isn&#8217;t that counterproductive, and&#8230; silly!<\/p>\n<p>Do I want to write higher quality code? Faster? Less buggy? And get more fun out of it?<\/p>\n<p>Of course!<\/p>\n<p>But I&#8217;ve tried before.\u00a0And reverted to old ways of doing it.<\/p>\n<p>This time, I want to infect myself with it.<\/p>\n<p>How? By trying harder. By making this &#8220;my way&#8221; of doing things. And by actually writing the tests first.<\/p>\n<p>It&#8217;s going to take more effort than that! \ud83d\ude42<\/p>\n<p>Today I got an opportunity to do just that. And I am surprised how I was able to kill a few bugs. Bugs that would have &#8220;bugged&#8221; me later.<\/p>\n<p>But why write the tests first?<\/p>\n<p>So I develop good coverage. So I design better. So I get instant feedback. Those are 3 very good reasons.\u00a0Not only that, but by first thinking about the tests, I will cover more corner cases; I will make my code testable.<\/p>\n<p>Do I really need more convincing?<\/p>\n<p>Not really. Benefits are clear. It&#8217;s just a matter of &#8220;doing&#8221; it.<\/p>\n<p>Lastly, to give some direction and insight on how to proceed, here are the three laws of TDD as per Bob.<\/p>\n<blockquote>\n<p>The Three Laws of TDD<br \/> 1) You are not allowed to write any production code until you have first written a failing unit test.<br \/> 2) You are not allowed to write more of a unit test than is sufficient to fail\u2014and not compiling is failing.<br \/> 3) You are not allowed to write more production code that is sufficient to pass the currently failing unit test.<\/p>\n<\/blockquote>\n<p>Martin, Robert C. (2011). The Clean Coder<\/p>\n<p>Ready to join the TDD camp?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am a TDD fan. I&#8217;ve been one for a long time. But I&#8217;m not a TDD practitioner. I don&#8217;t follow the TDD methodology of writing the test first, implementation second. Not yet. Uncle Bob convinced me to try. Again. Time to become a TDD developer!\u00a0Time to step up my code quality. I have said [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[42,44,45],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-better-coder","tag-goals","tag-tdd","tag-testing"],"_links":{"self":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=551"}],"version-history":[{"count":6,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":557,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions\/557"}],"wp:attachment":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}