Prasanna
- All
- Personal
- Sports
- Sun
- Tech
- Useful Code
Monday Sep 03, 2007
Test Driven Design
People may have heard about Test Driven Development, but I just reaped the full benefits of introducing test cases during design itself, but in a sligtly different way.Assume that you are developing a module and have completed some form of pseudo-code for it and it worked fine (like the way it worked for me). Then coding starts and the cycle goes like this.
Develop code according to the design specs -> Write unit tests, test rigorously -> Release the code -> Apply Patches as and when necessary.
But when you start writing test cases during design phase, it simplifies things so much that one never needs to undergo the pain of fixing several hard to determine bugs and modify the code (which makes it worse of course). Last week when I was developing a pseudo code for my module, it worked fine, but after introducing some 15 - 20 test cases this is what I experienced.
Test case Result Action
Test case 1 PASS N/A
Test case 2 FAIL Added an if condition in the pseudo code
Test case 2 PASS N/A
Test case 3 FAIL Failed to handle exception in code, therefore added exception handling
Test case 3 PASS N/A
Test case 4 FAIL Introduced a new method to handle this functionality
Test case 4 PASS N/A
Test case 5 FAIL Added a check to sanitize the input
........
........
........
........
Test case 20 PASS
All tests Passed finally.
Now after this phase, when I looked back my initial pseudo-code and the way it has changed after all these tests passed, there were lot of differences in my pseudo-code in terms of readability, robustness, security, etc (add other qualities of good code). BTW each time I did a code walkthrough to make sure my tests passed.
How did this approach made the difference? When I did the actual coding, things worked fine the FIRST time the module was executed and I just ensured that all the tests passed during execution without any major changes in code (of course there were minor issues, but those were due to coding errors and not due to design).
Now assume the case when these tests were not there during the design phase. Probably there would have been 15 - 20 patches which may have incurred painful changes to code each time, at the worst would have killed several hours of productive time.
Therefore, sooner the test cases are introduced, the better the life will be for developers and all it requires is some extra hours spent during design, thinking from an end user's perspective.
Posted at 04:26PM Sep 03, 2007 by prasanna in Tech | Comments[0]
Comments:

