Baby Step TDD
At one of the Softwareskammer’s sessions in Munich, we were introduced to a new practice of Test Driven Development called Baby Steps.
The Baby Step TDD came up as a solution for the problem of TDD when sometimes you write a test which forces you to implement too many changes in one step to make the test pass.
As known, the main cycle in the TDD is described as follow:
- Write a failing test
- Write code to make test pass (then goto 2, or if can’t think of more tests, refactor)
With the Baby Step we had to do the same cycle but with an extra constraint that it must be done in 2 minutes. So at the end of each cycle the test must be “green” (test passes).
Now, the most painful condition was that if you finish on red you have to roll back your changes to the last “green” state.
We had to write Java code printing diamond, as described in Seb Rose’s post, and use git for committing the “green” code at the end of each cycle or rolling back “git reset –hard HEAD” when it is “red”.
From my point of view, in spite of the fact that the rolling back after each red cycle drove me crazy, I think the method is good in a way that it forces me to divide the problem to small problems and write more cohesive chunks of code while trying to keep the test passing in 2 minutes.
Putting this practice in production, once understood correctly, will guaranty a better code quality on the long run; however, it may not seem a good idea for some developers, as it presents a relatively slow process.