Every time an engineer modifies a line of code there is a risk that they might inadvertently break something or make a mistake. Even extremely small, innocent-looking changes can have bad consequences: “It’s just a one line change” are famous last words before a system crash. Because every change is risky, we need a way to reassure ourselves that the code is working, both initially and whenever it’s modified. Tests are often the main thing that give us this reassurance.
As engineers, we usually concentrate on writing automated tests. This means we write test code that exercises the “real” code in order to check that it’s working correctly. Chapter 1 described how there are different levels of testing, and in particular, how unit testing is the level of testing that engineers typically deal with most often in their everyday coding. We’ll therefore concentrate on unit testing in these two final chapters.