> How do you make sure that the refactored class does the same thing as the old one?
This. This is the problem. The answer, with tests.
This. This is the problem. The answer, with tests.
Tests are simply the implementation of knowing what the code is expected to do. If you don't have any basis for that expectation, writing tests is meaningless - either you test the current behavior of the code, which doesn't help you change anything, or you test your imagined behavior of the code, which doesn't help you validate anything.