Chapter 13
Adding Tests to a Legacy Application

In the real world, you don’t always get the luxury of working on shiny new code. Reading a book like this can be a little bit frustrating because the examples all deal with nice, simple problems, usually in a new codebase.

We all know that software development isn’t really like that.

Even in the best teams we’ve worked on, there have always been a few dark and ugly corners of the codebase where nobody really wanted to go. People would sometimes disappear into there for days at a time and emerge exhausted and confused, blinking in the bright sunlight.

Like an old abandoned mine, those areas of the codebase are dangerous. The code is fragile, and the slightest change can cause other parts of the code to collapse and stop working. Everyone knows this, and that’s why people are reluctant to go in there: it’s stressful work.

If you had to go down an old mine tunnel, what would you do to make it safer? You would probably build some scaffolding to hold the roof of the tunnel up so that it did not collapse—just enough to help you get in and get out again safely.

You can think of automated tests like this. When you have to make a change to an area of the code that you know is brittle, it’s scary. What is the thing that you’re most afraid of?

Breaking something.

Automated tests can help you keep this fear at bay. If you make a change and other parts of the code start to collapse, the tests will give you a warning while you still have a chance to do something to correct it. But what if you don’t have any tests?

Even if you have recognized that automated testing can help your team write better code, the prospect of adding tests to a large legacy codebase can seem overwhelming. In this chapter, we’ll show you some simple techniques you can use to help to solve the problem gradually, giving you added benefit each step of the way.

This isn’t a technical recipe, but it will give you some useful techniques and encouragement if you’re facing this situation.

Let’s start with the first tool you’ll need when you enter the mine: a flashlight.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.158