{"id":3246,"date":"2014-02-23T07:56:09","date_gmt":"2014-02-23T13:56:09","guid":{"rendered":"http:\/\/bililite.com\/blog\/?p=3246"},"modified":"2014-02-23T07:56:09","modified_gmt":"2014-02-23T13:56:09","slug":"thoughts-on-test-driven-development","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2014\/02\/23\/thoughts-on-test-driven-development\/","title":{"rendered":"Thoughts on Test Driven Development"},"content":{"rendered":"<p>I was just working on adding autoindenting to <a href=\"http:\/\/bililite.com\/blog\/2011\/01\/17\/cross-browser-text-ranges-and-selections\/\" title=\"Cross-Browser Text Ranges and Selections\">bililiteRange<\/a>, and actually took advantage of the fact that I had an <a href=\"http:\/\/bililite.com\/blog\/2014\/01\/17\/unit-testing\/\" title=\"Unit testing\">automated test harness<\/a> in place for that library. So I actually used <a href=\"http:\/\/en.wikipedia.org\/wiki\/Test-driven_development\">test-driven development<\/a>: write the tests for the code that doesn't exist yet, then write code until they pass. It's an odd way of thinking, but I realized that it was more <em>fun<\/em> than my usual development cycle (remember, I'm a hobbyist, so if it ain't fun, I don't have to do it):<\/p>\r\n<ul>\r\n<li>Think of problem that needs solving (interesting)<\/li>\r\n<li>Write code to solve problem (interesting)<\/li>\r\n<li>Write demo\/test code (sort of interesting)<\/li>\r\n<li>Run test-fail test-mutter at code-recode debugging cycle (frustrating)<\/li>\r\n<\/ul>\r\n<p>With TDD, it's more like:<\/p>\r\n<ul>\r\n<li>Think of problem that needs solving (interesting)<\/li>\r\n<li>Write demo\/test code (sort of interesting)<\/li>\r\n<li>Run test-fail test-Write code to solve problem cycle (interesting)<\/li>\r\n<\/ul>\r\n<p>The tedious \"debugging\" phase is swallowed up in the interesting \"write code to solve problem\" phase and I enjoy it a lot more. There's still some tedious debugging if the <em>test<\/em> doesn't work, but the test code is simpler than the \"production\" code and generally easier to debug. I have had some problems getting my head around testing asynchronous code, but that probably means I need to simplify the whole system.<\/p>\r\n<p>Now I need to learn the discipline to keep to this style of development and I'll be a happier hacker.<\/p>","protected":false},"excerpt":{"rendered":"I was just working on adding autoindenting to bililiteRange, and actually took advantage of the fact that I had an automated test harness in place for that library. So I actually used test-driven development: write the tests for the code that doesn't exist yet, then write code until they pass. It's an odd way of [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3246"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=3246"}],"version-history":[{"count":3,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3246\/revisions"}],"predecessor-version":[{"id":3250,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3246\/revisions\/3250"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=3246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=3246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=3246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}