Unit Testing with Giant Robots
How fixing a piece of lego is just like debugging software
Yesterday I made a giant robot out of lego lions. It was a fun day. There’s something very satisfying about building with lego, not just in the final achievement- but in the actual construction. The way the system fits together; the little hidden intricacies only you will ever know about; the immediacy of holding something tangible.
While putting everything together, I discovered out that one of the pieces was subtly wrong. It caused one of the lions to have their legs permanently cocked- giving it a charming “happy go lucky” air. But ultimately meaning that when they needed to assemble into the giant robot, there were some technical issues.
Dragging out my collection of lego odds-and-ends, I set out to fashion a new configuration of leg joint so that the lion could send on all four feet again. And so I isolated the joint and defined the end condition (i.e. a successful robot lion leg should not stick-out sideways!). This meant I could approach it exactly how you’d approach a unit test in code.
By working with just a section small enough to completely comprehend, and having a tangible end condition; I could quickly prototype and ultimately discover a solution. And with that our giant robot could assemble and the universe would be safe again.
The lesson: The “isolate and condition” approach of unit tests is just as useful for discovering solutions as it is for preventing future problems.