When a developer embraces agile methodology the number one challenge for him is learning Test Driven Development(TDD). TDD is very different from traditional software development. When I started my agile journey, during initial months , found TDD very interesting skill to expertise on. A quality code base can only be developed by quality test code base.
Test driven development literally means writing tests first to develop a piece of code.
Remember Test First. Every Newbie agile developer will ask a common question “How can we test something That doesn’t exist yet“. I think this question seems very true too. But, before the actual implementation code is written , one can think of what will be the implementation code's behaviour and the state of the objects manipulated by the piece of code which is subjected to test.
Then start writing test for you imagined implementation code. The pattern of developing a new class in test driven way will be something like :
So, Three important Questions need to be asked :
- What is to be tested?
- How to test that?
- Do you want to test behaviour or state?
And, If one gets answers of these question then writing test code will be easier.The right approach is to break problem into small chunks.For example, if you are creating a Math Class then first think of add , then think of multiply or divide.So tasks involved in developing a Math class will be:
1. Write test first for add method and then implementation.
2. Write test for multiply method and then implementation and so on....
In agile it is believed that test code is the part of documentation. As a agile developer one has to really understand that writing tests properly and meaningfully is very important. Well written tests help code maintenance. Through well written test cases developer can pass thier ideas very effectively to other developers.