Retroactive Unit Testing
So we all know that we should be writing unit tests for our code, right? And on top of that we should be using behaviour driven tests like Behat as part of our continuous integration.
But what about those libraries, modules and websites you wrote ages ago? They don’t have unit tests…
But that old library works perfectly!
I hear what you’re saying, I’m sure it does. But what happens when you want to refactor that codebase or update it to modern standards? How can tell if the library still works when you’re done?
What I Did
I have recently been working on refactoring one of my Drupal modules, Address Field Lookup, with the aim of refactoring some of the codebase to a better standard. And it dawned on me that without unit tests I’d have a tough time telling if the module still worked when I was done.
So before starting on the refactored 2.0 module I implemented a suite of unit tests. Not only can I now reliably update the module the unit tests revealed 2 bugs in the existing codebase.