Why do we write tests? The most obvious reason is to see whether our code works. In the absence of a framework, we often do this manually at the time we’re adding a feature or while fixing a bug. But testing can do more for us than that.

As we build up a collection of testable scripts, we get the ability to test larger portions of our application automatically, something we can’t do manually with any regularity. A common approach in many programming languages is to build a pipeline of tests — you submit a pull request on GitHub or a merge request on GitLab and all the tests get run, giving you confidence that the changes didn’t break something you weren’t thinking about. This regression testing provides stability to your code base over time. With languages that don’t have a compilation stage, such as JavaScript and XQuery, there’s an added benefit to ensuring that syntax errors haven’t crept in.

Good tests also serve as a form of documentation. Hopefully your functions are well named with clear parameter names, indicating their purpose and form, but having tests where someone can look at exactly how your function gets called is about as clear as it can get.