Testing and refactoring go hand in hand. Refactoring is all about improving code without changing its behavior. Testing is all about making sure you don’t change the behavior while you are improving the code.

Read more at the source