2 ms·
> While it made refactoring feel 'safe' to do, it also slowed me down quite a bit. I find that unit tests actually make refactoring harder. The problem is, un
by quietbritishjim 4y ago
> While it made refactoring feel 'safe' to do, it also slowed me down quite a bit.
I find that unit tests actually make refactoring harder.
The problem is, unit tests need to be rewritten, or at least substantially shuffled around, every time you refactor. If you're making a "big bang" change for a major new feature, and that requires refactoring, then it's possible to justify that cost. But that's not how it normally happens.
Instead, a bunch of small changes over time usually make it apparent that the code would be a lot clearer and easier to maintain of the arrangement of responsibilities were different. It's already hard to ever justify the cost of that refactoring under any one small change. But add in the cost of updating all the unit tests and it becomes even more unlikely. Those updates also feels like demoralising busy work, whereas the actual change feels productive, so it also adds a human factor.
Overall, the net effect is that code with a lot unit tests ends up with a stagnant and confusing design.
As you say, a lot of the practical benefits can still be gained by end to end tests, while avoiding both the cost of writing so many tiny tests and the impact on long term design.