[Omaha.pm] Test driven development: RED, GREEN, REFACTOR

Jay Hannah jhannah at omnihotels.com
Fri Aug 4 16:16:47 PDT 2006


 
Hit a bug today. A specific message should have been logged as "WB V9",
not "V9 V9". The code that threw that log entry is 

      $return = sprintf(
         "%s %s %s [%s|%s%s%s%s] [%s|%s%s] %f",
         $req->get_gds,
         $req->get_sga,
         $msn,

... $req here is a Control::Multiplex::Payload::USW object. So, being
the agile developer (and other buzzwordy crap here) that I am I added a
test to USW.t that fails, demonstrating the bug:

$ perl USW.t
1..71
ok 1 - new()
ok 2 - get_payload()
ok 3 - get_type()
...
ok 67 - get_payload()
ok 68 - get_type()
ok 69 - get_segment()
not ok 70 - get_gds()
#   Failed test 'get_gds()'
#   in USW.t at line 158.
#          got: 'V9'
#     expected: 'WB'
ok 71 - get_sga()
# Looks like you failed 1 test of 71.

I then found the bug and patched it. And now ALL my tests pass! 

$ prove t/USW.t
t/USW....ok
All tests successful.
Files=1, Tests=71,  1 wallclock secs ( 0.63 cusr +  0.06 csys =  0.69
CPU)

Red/green/refactor, baby. I (re)learned that at OSCON last week. :)
http://conferences.oreillynet.com/cs/os2006/view/e_sess/8699

j


More information about the Omaha-pm mailing list