Testing
When we talk about refactoring, as we have already mentioned, we essentially mean rewriting the code in a better way (where “better” can have various meanings) without changing its behavior. This last point is crucial, and we have not yet delved deep enough into it. To ensure that the behavior does not change and, in general, to approach every refactoring with a high level of confidence, it is necessary to be covered by an adequate set of tests.
It may sound obvious, but a test is nothing more than a way to verify the functionality of certain software (whether it is a piece of code, a module, or an entire architecture) against a set of requirements. In practice, we’re saying: “Check that my code, given a certain input X, produces a certain output Y.” It can be much more complex than that, but for now, let’s settle with this explanation.
There can be various types of tests, as well as different approaches to writing them, as we...