Test (Drive Design) -> Code -> Refactor
Another discussion with Eli Lopian, check it here.
I would start out by saying that I agree to what he says, especially:
It is the process that will allow us to meet future requirements. A process that will allow us to change the design as the features grow.
I wouldn't call it process, but what the hell.
This, however, I disagree:
Lets recall the TDD process:
Write Tests -> Code -> Refactor (Design)
Notice that the Design stage is the LAST stage, it is not:
Design (For Testability) -> Test -> Code
In my view, the way it works is that you:
Write Test (Drive Design) -> Code -> Refactor
The idea is that writing tests is design, coding and refactoring is just making sure that it is working :-)
Comments
Your both right. The whole thing is design
Expressing your intent is design
Writing code is design
Simplifying is design
Introducing or removing levels of indirection is design
The whole point of TDD is a design technique that encourages loosely-coupled architectures. When you are writing your initial test, you are designing what the API looks like. You are pinning down expected functionality. You then write the simplest code possible (but no simpler) so that you have a working system. Then you look for opportunities to improve the design and refactor to your deeper understanding of the system. As Keith says above, it's all about design. It's about avoiding big design up front (BDUF), which has plagued our industry for so many years. It's about writing flexible software - software that can be changed easily as requirements change and knowledge is gained. I'm probably preaching to the converted as most folks reading your blog already know this.
I agree that the biggest design component of TDD is the test writing, it is driving the design of the responsibility and interaction of the components.
The refactoring step keeps you focus on simplicity in making each test pass (since you save refactoring for later). So, yes the refactoring does design the class, but it is implementation design.
Sometimes in the refactoring you decide to pull components out of the class, but if you are focused on testing and single responsibility, you test drive those before you get to the refactoring phase.
Fully Agree. The test actually is the design stage, as when writing the tests you're designing the classes, methods, how they work and interact. It is as you said Test Driven Design.
Comment preview