{"id":186,"date":"2018-10-08T10:42:37","date_gmt":"2018-10-08T10:42:37","guid":{"rendered":"http:\/\/67bricks.com\/blog\/?p=186"},"modified":"2018-10-08T10:42:37","modified_gmt":"2018-10-08T10:42:37","slug":"testing-test-driven-development","status":"publish","type":"post","link":"https:\/\/blog.67bricks.com\/?p=186","title":{"rendered":"Testing Test Driven Development"},"content":{"rendered":"<p>In our dev meeting, we discussed Test Driven Development. So, of course, we did it TDD-style: we started off by asking whether everyone knew what TDD is; and then testing that; and then asking more questions about TDD until we got a failing test &#8211; i.e. several people who didn&#8217;t know. Then we updated our knowledge of TDD until we didn&#8217;t have a failing test, and iterated&#8230;<\/p>\n<p>We agreed that there are many benefits to using TDD, of which &#8220;ending up with a working test suite&#8221; is only the most obvious:<\/p>\n<ul>\n<li>Allows incremental development, so you are able to run the code as you&#8217;re going along<\/li>\n<li>Provides documentation for how the code works<\/li>\n<li>Helps you to get a feel for how the code will work as you&#8217;re writing the test<\/li>\n<li>Proves safety, confidence, and a greater ability to refactor<\/li>\n<li>Writing a test beforehand means that you are forced to have a failing test<\/li>\n<li>Forces a different mindset &#8211; because you&#8217;re thinking about your design and API as you write<\/li>\n<li>Helps you concentrate on what&#8217;s relevant to the task at hand, rather than doing unnecessary work<\/li>\n<li>Encapsulates features nicely &#8211; encourages better organization<\/li>\n<li>Helps keep focussed on the problem, and keeping the solution simple, rather than solving unimportant problems<\/li>\n<\/ul>\n<p>But, we concluded that while many of us used TDD for some of the time, it wasn&#8217;t true that all of us were using TDD for all of the time. So, given all these great things about TDD, why aren&#8217;t we using TDD for everything?<\/p>\n<ul>\n<li>We&#8217;re lazy<\/li>\n<li>It takes longer to get to a result &#8211; longer term benefits but a short term cost<\/li>\n<li>Not as good if you&#8217;re exploring<\/li>\n<li>Some types of test are hard to write<\/li>\n<li>Slow feedback loop for some types of test &#8211; e.g. some integration tests<\/li>\n<li>Limited framework support<\/li>\n<li>Working in an existing codebase that has been developed without TDD<\/li>\n<li>Working with frameworks that have been written without testing in mind &#8211; particularly older frameworks<\/li>\n<li>Working in very data-heavy projects, based on mutable source data<\/li>\n<li>TDD is a bit less useful when the language is more focussed on the problem domain (e.g. C#) rather than more focussed on technical issues (like C++)<\/li>\n<\/ul>\n<p>We discussed the level that we were &#8220;pure&#8221; in our application of TDD &#8211; whether we were always using a strict, Kent Beck approved &#8220;write the most minimal test, write a dumb implementation that just passes that test, then add more tests and refactor&#8221;. We concluded that we mostly weren&#8217;t &#8211; the range of TDD-like approaches that we use are:<\/p>\n<ul>\n<li>Pure<\/li>\n<li>Use a hybrid approach &#8211; write some minimal tests, write a real implementation, and extend the tests to cover edge cases<\/li>\n<li>Write TDD-style\u00a0 when it will actively speed up implementing a feature due to better turnaround time<\/li>\n<li>Write out the specs first, and then implement the code based on that &#8211;<\/li>\n<li>Write tests to help the code reviewer understand what&#8217;s been written: sometimes before writing the code, and sometimes after<\/li>\n<\/ul>\n<p>We discussed a potential pitfall we had sometimes hit with TDD &#8211; that sometimes it is tempting to keep hammering at the code until the tests pass, rather than to step back from it to reconsider the overall strategy.<\/p>\n<p>In conclusion &#8211; we use TDD a lot of the time, but we tend to use hybrid approaches rather than a strict pure approach.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our dev meeting, we discussed Test Driven Development. So, of course, we did it TDD-style: we started off by asking whether everyone knew what TDD is; and then testing that; and then asking more questions about TDD until we got a failing test &#8211; i.e. several people who didn&#8217;t know. Then we updated our &hellip; <a href=\"https:\/\/blog.67bricks.com\/?p=186\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Testing Test Driven Development&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":1,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/187"}],"wp:attachment":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}