The usefulness of automated testing varies greatly in the world of software development. We know it makes sense for libraries that are relied upon by a community, but it's difficult to rationalize the time spent on developing tests for one-off custom Drupal modules.
Some reasons for that are:
- Code dependence on a large framework.
- Processor time required to build a site and database for each individual test.
- Development time required that can increase project costs.
- Risk of code changes and frequency is low. Meaning–you may not need to change code often, and if something goes wrong, the impact is small, and low stakes.
But this doesn't mean there are not one-off projects that can benefit from some automated testing. One such example might be something I found myself developing for a recent project: A module that introduces functionality that uses an external authentication system for logging in users.
Reasons FOR developing automated tests for this module include:
- High risk relating to customer's inability to log in if something goes wrong.
- Dependency on a bespoke external system that we have little control over.
- A wide array of expected outcomes based on the external response, and what information is stored locally.
- Manual testing the login process for a variety of scenarios is tedious.
Unless you have experience developing contributed code where testing is required, there can be a lot of friction to getting tests running for a custom module that has a lot of dependencies we have always had the pleasure of assuming just work. Online resources for testing unique custom modules are few and far between, and what does exist is often contrived. In this article, I'll show how I set up a test class for a project's external authentication module and discuss the pitfalls along the way.