The real joy of writing unit tests

2 min read Original article ↗

Duncan Grant

At this point, articles evangelising test driven development have been done to death. However, I think they often miss the big selling point to people who have tried or been forced to write tests and never enjoyed the task. Programmers who work alone, or small teams working on smaller projects will often never seen the point of introducing tests which appear to be more of a hindrance than a help. Too often TDD articles lead with the virtue of how tests are good for teams or good for maintaining code bases before they become legacy, but I’m going to tell my story of test driven development and explain the understated reason that unit tests could be useful to you personally in your next project, no matter how small that project may be.

I think some of the most fascinating lessons to learn are the ones which have been right under your nose the whole time, but never truly grasped, until one day everything clicks and you are in awe that it has taken so long to discover something that makes so much sense. For me, such a lesson came when I needed help and test driven development showed me the path.

2010 was the year I first ‘got’ JavaScript, when I built a bookmarklet to parse, read, explore and edit RDFa from webpages. Reading online books such as Addy Osmani’s essential js design patterns, really opened my mind to the power of JavaScript. Before the age of let and const, arrow functions and classes and even before promises, when we were still wrangling with callback hell, I found that JavaScript was flexible enough to write it in…