Posted on
May 8, 2008 08:05
by
JP
tdd
Categories:
Actions:
E-mail |
Permalink |
Comments (0) |
Trackback
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.