Musings

Testing: the most important thing you will ever do

If there’s any one recurring theme that has come up time and time again over the last two or so months that I’ve been on this journey it is this:
TEST TEST TEST. TEST EVERYTHING. TEST ALWAYS.

Most of the time, you will be writing software that someone else will come and modify at some point in the future. For that matter, you may come back in a few months’ time and realise that there’s a better way of doing it. And that’s perfectly ok, AS LONG AS THERE ARE TESTS.

Picture the following:
You are exploring your codebase, reading through snippets of code, and you realise that there is a class which seems to have some serious refactoring potential, but there are no/limited tests covering the code. Sad face time :(.
You’d be too scared to modify the code (who knows if you have possibly missed a crucial point and inadvertantly broken the code in production?). Chances are if you need to make changes you’ll stick an if statement in there and be on your way – you know the existing code WORKS, it’s just not very pretty. Come back in a few years’ time and this class has become a gigantic nightmare that no one wants to touch with a barge pole and we’re spending millions to replace it with a new application (extreme scenario!). More likely, it’s a massive legacy application that has many people working on it. It may still work as expected, but in the new world something that could potentially have been a 5 minute change has now become much more complex.

Before this causes you to spiral into depression, imagine this much happier scenario:
You are exploring your codebase, reading through snippets of code, and you realise that there is a class which seems to have some serious refactoring potential, AND THERE ARE BEAUTIFUL WONDERFUL TESTS COVERING EVERY SCENARIO POSSIBLE!!! Time to weep with tears of joy :D.
Now, you could make any changes you want (within reason), run the tests, make them green and commit. You’d know if you’d broken something straight away, and if you had you could just rollback and everything would be right with the world and and and… oh happy days.

Moral of the story: TEST.

That is all.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s