chad.davis (234) [Avatar] Offline
Refactoring seems, to me, to be the most important aspect of TDD. And it's clearly the presence of the tests that make refactoring so easy and successful, since they provide a safeguard against breaking things with heavy refactoring.

This leads me to then have concerns about refactoring the tests themselves. Since the tests themselves kind of serve as the specification of your system, they are in some ways as important as the code itself. So, if we are scared to refactor the code, without tests, then shouldn't we be scared of refactoring the test themselves. What servers to protect the integrity of our tests as we refactor them?
lkoskela (66) [Avatar] Offline
Re: refactoring test code
Hi Chad,

Apologies for taking so long to answer - I had dropped out of the habit of checking this forum.

Refactoring tests without tests for the tests is not an issue for me for two reasons. First, the tests I write are typically less complex and with less inter-dependencies than production code and, hence, pose less of a risk. Second, the production code serves as a test of sorts for the tests themselves. If I refactor a test and they stop passing I know there's something weird going on and proceed to investigate, backtrace/revert, etc. When the tests continue passing after a refactoring, I sometimes double-check by intentionally injecting a bug into the production code to verify that changing the production code in a certain way fails the tests I've touched in an appropriate manner.