When we have completed writing our tests, as briefly outlined in this chapter, we will have created a great trap for future bugs. Each time we run our tests, any changes to the expected behavior will stand out as failures for us to correct. This ensures that as we continue refactoring, we will be doing more good than harm to our legacy codebase as a whole.

In addition, because we now have a working test suite, we can add tests for any new behavior extracted from our legacy codebase into our application classes. Each time we create a new application class method, we will also create a passing test for that method. Each time we modify an application class method, we will run the test suite so that we can find bugs and breaks before they make it into production. We will rejoice when our tests pass, and we will rejoice when they fail; each outcome is a positive sign when it comes to modernizing our legacy application.

With that, we can continue our modernization process. The next step is to extract our data retrieval and persistence behaviors from the page scripts and into a series of classes. Generally, this means moving all our SQL calls to a separate layer.