Just stating the obvious, here, but unfortunately it’s also something that many teams miss:

Code Refactorings should be happening continously

Refactoring cannot be something that is scheduled or aligned with the QA process – waiting to manually retest a system after each change. Refactoring should happen every day, lots of times per day. There is no other way to the quality code.

But how do we make sure refactoring does not change (damage) existing functionality? TESTS.

We are all, more or less, clear the JUnit tests are just one part of the tests to be written, functional testing should also be automated. No way it can happen as frequently as it is needed when doing it manually! Automating functional testing is a big deal.

There are tools for that, too. Like this nice one: