Today was the first day i started doing
Test First Development. I had been thinking that i was doing TDD for the past couple of months. After my TDD training during the last 3 days, i realised that all i had been doing was just glorified unit testing and not TDD.
I used to have a pre-conceived class diagram and the methods which should be present in a class and then go about writing
Junit and
Java classes in parallel. What i learnt and was a bit surprised to learn was TDD was nothing but it..
I started working on a web application today and wanted to give what i learnt a shot. The application was a typical web-app. There was a screen which had a list of search results. On clicking on a row, it was supposed to bring the details of the entry..
Typically i would have started off with a basic class diagram and a sequence diagram (if time permits) and then would have set out coding... Today i did the opposite...
- I first came up with the list of test cases.. I was surprised to come up with 24 high level test cases for what seemed a not so complex problem
- Then picked up the smallest test case.. This is what Brian Button taught me in my class. Start off with a small test case and then build towards the complex ones..
- I wrote a test which did not even compile.
- Then did just enough to make sure the test compiles.. Then ran the test and saw it failing. But that's what you expect..
- Then wrote a hard-coded implementation to make the test pass..
- Kept doing up to three tests until i saw a pattern emerging.. The way interfaces emerge out of nowhere and a beautiful inheritance tree emerge was so pleasing to see.
- By end of the day i had a working system of high quality.. Not all tests were implemented, but the ones that were implemented was beautiful to see..
Compared to my last 7 years of Java experience, it would have at least taken 3 - 4 days before i started coding and within 3 to 4 hours of coding, i would have changed my design at least a little bit... It really does make sense developing this way.I gave the estimate for this work before the agile class. It was assuming an RUP way of development. It will be interesting to see how much effort i actually take with this approach.
I should also try to learn how i do TDD f0r the code that lives close to the persistence layer. I am not sure how to get that done.. If anyone has any ideas do post it in here...
Thanks for reading, am sure i will be posting more of my experiences...