Could you give a (small :-) code example that we could talk about that shows a bug that you missed during TDD?
I'm going to have to owe you that one for the time being, at least as far as code goes. There are three bugs I can think of. Probably the lamest happened with the code I just recently posted. I had a battery of around 40 tests already, all succeeding, when suddenly the test suite started seg faulting while setting up tests whose fixtures where very similar to those of earlier tests.
To make a long story short, and much simpler than it appeared originally, the problem looked like this:
Basically, my code had not taken into account the fact that as hashes grow, perl will allocate more memory and move the (now overcrowded) entries to more spacious digs. When this happened, my iterator was left with a dangling pointer, leading to the seg fault. Shame on me for not thinking about this from the beginning, but my point is that this bug was there all along, but my "simple tests", testing simple things, one-feature-at-a-time, missed it entirely. As BrowserUk said, if the programmer writes his/her own tests he/she is bound to omit the tests that would make manifest the nasty bug; the same lapse that led to the bug, leads to the missing test.my %hash = map +( $_ => 1 ), ( 1..$reasonable ); my $it = Hash_Iterator->new( \%hash ); $hash{ $reasonable + $_ } = 1 for 1 .. $a_few_more; $it->start; # BOOM!
The hallmark of this and all other nasty bugs I've run into while doing TDD, is that they kick in only after a particular extended sequence of manipulations that leaves the system in a state not foreseen by the programmer. Typical TDD tests tend to miss these bugs, because these tests, necessarily, tend to have very short horizons. The more elaborate the sequence of steps to bring the system to an unsound state, the less likely that the unknowing programmer will think of writing any test that will bring on the problem. (Note that the tests that elicited the bug I just described were not expected to fail the way they did. I was testing something else entirely. It was just good luck that they picked up this problem.)
This is a very interesting subject. I have been meaning to write a meditation/book review on TDDBE. I hope to give more details then, including, hopefully, some real code.
I think that, as you say, I probably have not quite gotten the hang of TDD yet, which accounts for some of the problems I'm having with it. But I also think that the formulation of TDD given by Beck, which is the only one I know, has been dumbed-down beyond the point of usefulness. But this is a subject that deserves more time than I can give it now.
the lowliest monk
In reply to Re^9: Self-testing modules
by tlm
in thread Self-testing modules
by DrWhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |