|
|
|
|
|
by BlackFly
1253 days ago
|
|
Unit tests (class or method as the unit) hinder refactoring by binding to low level implementation details. When you refactor, by definition you are changing what the factors (units) are. Generally, your unit tests will then be testing implementation details that no longer exist. By strongly coypling to implementation details, unit test suites suffer an extremely large ripple effect on refactoring. Tests in general can only help you refactor code at a lower level of granularity than what you are testing. Something lower than unit level is a contradiction. Of course, you can instead test business behavior which isn't as volatile in refactoring and change your definition of unit to be a unit of practical business requirements... |
|
But a developer looks at f(a,b) and realises a new implementation could be 10x faster.
The developer re-writes the function, the tests still pass. Without that test they couldn't be sure their rewrite didn't break the expected behaviour.
What you're talking about is changing interfaces and structure when refactoring. Yes, unit tests can make that more painful. But you bin your old tests and write new ones.
If your unit tests are not cheap to dispose of, run or rewrite ... that's your core problem.
If your unit tests are not testing discrete units, instead testing the combined behaviour of many units (the re-factoring of structure pain) ... then you have bigger issues than the tests; namely understanding the difference and applicability between unit and integration tests.