News for hackers. Stuff that matters.
Re:Refactoring vs. defactoring by eyelidlessness on Wednesday October 27, 2021 @08:17PM (#29020797)
I routinely refactor without changing tests, and it’s a primary concern when I define interfaces and determine what to test. For what it’s worth:

- This works best if you actually embrace BDD to test for behavior rather than results. The behavior is less likely to change, and along with points below so too are the interfaces under test.

- I find the least test change in statically typed languages where defining types is the first “test”. Behavioral interfaces become much more stable as you define them if you actually know what they are upfront.

- Both of the terms “integration test” and “unit test” discourage this. Validating what your program actually does usually sits somewhere in the middle, and allows you to encapsulate a lot more of what would otherwise likely change in tests.

- Stricter interfaces fare better than looser. That doesn’t mean give up on the Robustness Principle, but it does mean don’t let it become infectious (I now want to blog about the “color” of functions which accept “options” or other miscellany). The sooner you parse/validate/have concrete and reliable types, the less your code under test and the tests themselves will change.

And that, while it’s my last point, is the most important: narrow types early. Get stability inside the seams of your program.

There are no comments on this comment yet.