Deal of the Day

Home » Main » Manning Forums » 2007 » Test Driven

Thread: refactoring test code

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Pages: 1 - Last Post: Nov 12, 2009 3:48 PM by: lkoskela
chad.davis


Posts: 235
Registered: 3/1/06
refactoring test code
Posted: Nov 9, 2008 2:36 PM
  Click to reply to this thread Reply

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

Posts: 66
From: Helsinki, Finland
Registered: 4/14/05
Re: refactoring test code
Posted: Nov 12, 2009 3:48 PM   in response to: chad.davis in response to: chad.davis
  Click to reply to this thread Reply

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.

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor