Twitter GitHub Facebook Instagram dirv.me

Daniel Irvine on building software

TDD for the web is both hard and easy

5 August 2014

Test-driven development for the web is both hard and easy.

It’s hard because the mental model of a website we hold is hazy. There are numerous moving parts, each vastly different from the others. Take for example the web browsers (plural--since there’s not just one), which act as the runtime hosts for our code. A web browser is a mature and complex piece of software that evolves at a blistering rate. Competing web browsers have subtle differences which developers must be aware of and guard against. In contrast, test frameworks like Teaspoon are immature and suffer teething problems--not surprising, since the idea of having automated tests for web front ends is still seen as revolutionary.

Our brains struggle to understand this bazaar-style architecture. We panic when we think about all the dozens of ways it could go wrong.

On the other hand, TDD for the web is easy because all those moving parts give us a number multiple insertion points to tinker with. And the DOM itself has a simple textual representation which can be decomposed into chunks, allowing short, sharp tests that operate on specific parts of our JavaScript. That means we can create many small independent tests with just a few lines of code each. Try doing that with a desktop UI.

About the author

Daniel Irvine is a software craftsman at 8th Light, based in London. These days he prefers to code in Clojure and Ruby, despite having been a C++ and C# developer for the majority of his career.

For a longer bio please see danielirvine.com. To contact Daniel, send a tweet to @d_ir or use the comments section below.

Twitter GitHub Facebook Instagram dirv.me