I am trying to practice TDD.
As I understand it, doing TDD should go like this
- I write a test list for the interface/class I am going to develop.
- I start with the easiest yet to implement test from my test list.
- The test gets written, no implementation code yet.
- The interface of the class gets written to make the code compile.
- The test gets run, giving me a failing test.
- The implementation gets written, making the test pass.
- Refactor the code written.
- goto 2.
The problem I have is that when I arrive at point 6 & 7, at some point in time I invariably come to the conclusion that the implementation I just wrote should be delegated to another class.
What should a true TDD'r do at this point?
- Leave the existing test list alone for a while and create a new one
for the new class. (but the same problem can arise when implementing the new class) - Go the interaction based way of testing and Mock the new class, continue with the testcases of the class you are working on and come back later to create a correct implementation of the mocked class.
- This situation should not present itself, I have not thought out my initial design well enough. (wouldn't that defeat the purpose of TDD).
I would love to know how other people handle these situations.