by arkh · 5y ago · 0 comments
When I am doing legitimate refactoring in simple steps by the book, unit tests are helpful and speed it up. When I am rewriting, I see your issue.
For example, a sprout method or sprout class refactor do not change the tests.
Integration tests are nice, but they don’t give me enough confidence about the specific part of the system I’m altering.
If you find yourself doing this frequently though unit tests might not be ideal for your situation.
Well, unit tests verify a contract. If a developer wants to change code but is incapable of respecting a contract (i.e., preserving old invariants or adding new ones that make sense) then he should not be messing with that code at all, shouldn't he?
In that sense alone, it's quite clear that unit tests pay off and add a lot of.value, namely in avoiding needless regressions from Rambo developers who want to change code without caring if it even works.
This is the most important thing. Rambo can delete all the unit tests he wants in his MR; our discussion will be about whether:
- the contracts have changed.
- the unit tests shouldn't have been there in the first place.
- he's violating contracts
If you have reached the point where you feel tests hinder refactoring then you have two paths: a/ learn to write smaller, SOLID classes, or b/ meh unit tests are stoopid.