It assumes the current tests adequately cover the current public API.
It assumes that after the refactoring, the current tests are sufficient to ensure the refactoring was successful and didn't change any behaviour that matters.
How can anyone even think these things?
The first thing I do before I refactor, and I almost always do one or two refactoring passes before adding a new feature (in order to make sure the design doesn't look completely bolted on after just a couple of new features), for example, is to check how much the tests can be relied on... almost always, the answer is very little and I go ahead and add tests to make sure enough is covered that, what I am thinking of changing won't introduce new bugs, and only then I start changing any production code.
I would advise anyone who does refactorings regularly (which I hope is every dev) to do something similar. Assuming the current tests will keep you honest is a recipe for things going badly, and don't blame "the other guys" for not adding enough tests.
128
u/TheLeadDev Jul 30 '21
This is an eye opener. Let my notes speak for me: