Testing After The Fact Still Influences Design

In the past, I have stated that backfilling unit tests, that is, writing tests for existing code, is not really doing TDD. I think to some degree I was wrong. I said this because of a hasty observation. If code already exists, then it has been "designed", hence, my tests are just making sure that the code works.

This is not really true. Today, I observed that the act of writing a test helped me find several potential problems in an existing method. Also, I found the method somewhat difficult to test. By difficult, I mean that I found myself setting up a lot of pre-conditions in order to get the test to run. This was my clue that some refactoring was in order. Once I was finished, I was left with something far superior to what I had started out with.

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 21. 2008 13:48