martes, 9 de junio de 2015

Teaching TDD

I decided to show/teach/encourage to try TDD with my colleagues at work. A few of my colleagues and I had some katas before. They were quite successful and particularly 2 of them sounded quite excited.

On my way to invite more people to try TDD, last night a colleague of mine and I had a kata, the wordwrap kata. Unfortunately it was not as good as the previous ones.

We started typing a test, then make the class and the method. Everything compiled and got the red bar! We went green and started adding more tests, red bar turning into green for about 6 times. Then we decided to add a more complex test, which was supposed to be the final test.

During this final test we struggled quite a lot and couldn't get the green bar. On the opposite we ruined two tests. That was quite frustrating, it was like 8:20 pm and decided to continue today.

On my way home, riding my bike I was still thinking how it could have failed. I had done that kata before a few times but this was totally different. I started analyzing our kata and thought that our main mistake was to refactor too lately, perhaps. When we decided to implement the last test, our code was too complex.

Maybe we were tired and couldn't think about refactoring instead of forcing it to turn green.

Today we refactored what we needed and happily turned green. Several lessons learned during this kata. Perhaps the most important is to have a bottle of water next to the keyboard to force us stop for a while and try to rethink what we were doing!