4

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 ...

Get Refactoring in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.