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.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

prasanna

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today