Monday, May 09, 2011

TDD


This is a quick post to introduce what is TDD. Because John Ferguson explains it so well, I will just copy his definition. I can not do it better, for now.


By John Ferguson Smart

"TDD is a working methodology that drives every development step. Helps the developers to stay focused in the requirements and not forget them while trying to solve a specific algorithm or while working with a sub-technology, language or tool.

TDD have three phases. First starts writing a failing test. This step is like writing what is the required behaviour. This is also an example of what the code does. Here the developer should write the interface that declares what are the available services. It is important in this step to divide the responsibilities and do a proper design by focusing always in ideas like reusability, low coupling, high cohesion, readability, simplicity (please no clever code, no high tech over complicated code 'intelligent'). Each method of the interface should do simple things, like get or set a value object, write or read a file, do specific calculation, do one checking status, only one simple task.

Those failing test are different from implementation test. Failure test, tests the behaviour and the implementation tests, test the code, one specific method. 

TDD frameworks are easyb, jbehave, for high level testing = acceptance testing. JUnit is low level testing. 

Acceptance testing should test the service layer application, because is like run the code on behalf of the users, testing the behaviour.  

In a second step the developer implements the interface. Here is simple code, implementing methods as simple as possible. If is not possible to keep it simple the method should be divided in private methods. 
If still not possible something in the interface is not good enough designed and or the task is out of the scope. 

Finally the last thing de developer need to do is refactoring if it is necessary. And because the TDD methodology helps in doing a clean design, the refactoring should be clean and easy to do when it is required."

Posted by Marc Andreu.

No comments: