In my experience the nasty bugs come, literally, from where I least expect them, and this is crucial. There is no hope that I will somehow write a test to catch such a bug, no matter how hard I try, because the best I can do is test those aspects that I regard as potential sources of problem. And in fact, during my recent applications of TDD, some very nasty bugs have arisen despite a rigorous adherence to TDD principles.

Of course I'm not saying that TDD guarantees zero bugs, no testing strategy can do that. However it's been my experience, and the experience of others, that TDD dramatically reduces the number of bugs.

However TDD is a skill, and it takes time to learn and get good at it. It took me a good few months before I really got it. Some of the mistakes that I made were:

What helped me grok TDD was dropping down to insanely small increments. Write the most obviously stupid non-general code to get the test to pass as quickly as possible. Then write a test to break that really stupid code.

(These bugs have all become manifest after the system had "aged" a bit and attained a particular—and as it turns out ill-conditioned—state; therefore, all the simple tests that tested functions to produce expected outputs missed these "history-dependent" bugs. I'm beginning to see that the functional programming folks are on to something with their avoidance of assignment and side effects.)

Since you're still getting a large number of nasty bugs my suspicion is that there are possibly some elements of TDD that you're missing.

Could you give a (small :-) code example that we could talk about that shows a bug that you missed during TDD?

Also, I find interesting the difference between your take on TDD and that described by Kent Beck in his widely cited TDD by Example. Beck uses "test first" only as a precondition for adding functionality to his software. I.e., he says that one should not write any new code in one's application until one has written a failing test that will succeed only after the new code has been written. He makes no mention of writing tests specifically designed to make the software fail.

It's the same thing from a different perspective.

If you're using TDD then every time you write a test you should expect that test to fail. It's the test failure that drives the design/development (hence the name :-)

With TDD you don't stop when all the tests pass, you stop when you can't write any more failing tests.


In reply to Re^8: Self-testing modules by adrianh
in thread Self-testing modules by DrWhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.