How do you test/change untested and untestable code? | Lately I had to change some code on older systems where not all of the code has unit tests.  

Before making the changes I want to write tests, but each class created a lot of dependencies and other anti-patterns which made testing quite hard.  

Obviously, I wanted to refactor the code to make it easier to test, write the tests and then change it.  

Is this the way you'd do it? Or would you spend a lot of time writing the hard-to-write tests that would be mostly removed after the refactoring will be completed?