Test Driven Development

“We are uncovering better ways of developing software by doing it and helping others do it.”


Test-driven development (TDD) is a technique for ensuring that your code does what you think it does. It’s particularly relevant for JavaScript, with its cross-browser incompatibilities and hidden gotchas. With TDD, you express your intentions twice: once as a test, and once as production code. If the two approaches don’t match, your tests fail, and you’ve caught a bug.

TDD is a great way of catching the majority of programming errors. It’s not perfect, of course – in particular, it can’t tell you when your assumptions are wrong—but it’s very good at catching the kinds of bugs JavaScript is prone to.

TDD as a Pre-requesite for Professionalism

Ignaz Semmelweis in 1847 achieved a six-fold drop in his maternity ward’s mortality rate by simply having doctors wash their hands before examining pregnant women. Semmelwies tried to convince his peers to adopt hand-washing as a discipline. They resisted for over 60 years. The reasons for their resistance sounded much like the articles we’ve seen of late claiming that TDD is dead.

Doctors at that time did not wash their hands. They saw no reason to wash their hands. To them, cleanliness and disease were utterly unrelated. To us, in the 21st century, that’s difficult to believe; but just 167 years ago it was just as hard to believe that washing hands was anything but a fools errand.

Were these doctors unprofessional? Of course not! They were doing the best they could with what they knew. Their distrust of Semmelweis seems unreasonable now, because Semmelweis was right. But it’s hard to fault those doctors for not following every fool fad that came along. It took time, and unfortunately it took a lot of misery and death, before hand-washing was adopted as a medical discipline.

If any doctors today failed to wash their hands, we’d call them unprofessional and drum them out of the profession. Such actions would be intolerable. But back then, those doctors who rejected Semmelweis where honorable, respectable, and professional. They weren’t evil. They weren’t even stupid. Their only fault was that they were human.

Something Must Change

Software casualties are mounting at an accelerating rate. Our society as a whole is becoming more and more dependent on the software we produce; and the failures grow in significance with every passing year.

Something must change … or we are headed for a catastrophe of existential magnitude.

If I am right… If TDD is as significant to software as hand-washing was to medicine and is instrumental in pulling us back from the brink of that looming catastrophe, then Kent Beck will be hailed a hero, and TDD will carry the full weight of professionalism. After that, those who refuse to practice TDD will be excused from the ranks of professional programmers. It would not surprise me if, one day, TDD had the force of law behind it.


Let’s code javascript has an interesting collection of recording for real-world javascript development. This site has sections on TDD and refactoring.

Testing in Node.js: “A test driven development cycle simplifies the thought process of writing code, makes it easier, and quicker in the long run. But just writing tests is not enough by itself, knowing the kinds of tests to write and how to structure code to conform to this pattern is what it’s all about. In this article we will take a look at building a small app in Node.js following a TDD pattern. This article uses Mocha and Chari.

About Cecil McGregor

As a software developer with many years experience, I am offering some of the many insights learned through the school of hard knocks. My passion is writing software! And I like to write superior software. I try to follow current trends and techniques as I apply them to my everyday work.
This entry was posted in software, test and tagged , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.