Skip to main content

Dealing with icky code

Most, if not all, software projects have some code that is difficult to work on.

Maybe it was written a long time ago or it performs some difficult or complex logic.

It may not follow modern best practices and, most likely, isn't covered by automated tests.

No-one wants to work on it.

But, what happens when it needs to change?

How can you do it and be confident the change doesn't break the existing functionality?

Before you make any changes, identify the use cases of the current code and cover them by writing automated tests.

Functional, web or browser tests allow you to make HTTP requests to an endpoint and make assertions on a response, and ensure it returns the correct status code and content, rather than focussing on the implementation details.

If you need to test an existing Drupal website, use Drupal Test Traits.

Once you have tests in place, you can make the required changes and ensure the original functionality still works by running them and checking they still pass.

Hopefully, you'll have written tests for the new functionality, so the test suite will start to grow.

Was this interesting?

Subscribe to my daily newsletter for software professionals on software development and delivery, Drupal, DevOps, community, and open-source.

About me

Picture of Oliver

I'm a certified Drupal Triple Expert and former Drupal Association staff member with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.