Re:How to avoid brittle code
by dllthomas on Friday April 01, 2016 @12:53PM
(#11406357)
> Pretty much by definition, a refactor of code should not change its behaviour.
Quite precisely by definition, perhaps for other reasons as well :-P
> My tests usually assert on behaviour observed at the boundaries of modules, so they should still pass during refactorings.
I find the kind of refactoring that most desperately needs the support of tests is changing the boundaries of the individual units. Unit tests can still arguably be useful there in making me clarify the changes I'm making to my interfaces... but they do need changing, and I can't be quite as confident that nothing is breaking if I'm changing both code and tests in tandem.
Quite precisely by definition, perhaps for other reasons as well :-P
> My tests usually assert on behaviour observed at the boundaries of modules, so they should still pass during refactorings.
I find the kind of refactoring that most desperately needs the support of tests is changing the boundaries of the individual units. Unit tests can still arguably be useful there in making me clarify the changes I'm making to my interfaces... but they do need changing, and I can't be quite as confident that nothing is breaking if I'm changing both code and tests in tandem.