Mainly Tech projects on Python and Electronic Design Automation.

Thursday, December 04, 2008

Yet Another Blog Entry On Doctests.

Doctests are a current hot Python blog topic. I thought I would point out that many of the bloggers, especially those pointing out its problems, seem to be seasoned Pythoneers, aware of alternatives and so able to compare doctesting with other forms of testing..

I've found that there is a significant number of programmers out there who just don't write reusable and maintainable tests at all. They may test to ensure their program 'works' when they wrote it, but that is all - job done, finito!

Doctests perform the very important task of lowering the entry point to the subject of testing. Novice pythoneers ready for exposure to testing are likely to have used the python shell to "try things out"; it is a small cognitive step to point out that by cutting and pasting those explorations from the shell into a docstring and adding some "magic sauce" to invoke it, you get a test. A trainer can then move on to the "why" of tests with the student thinking "I do most of it anyway", rather than thinking that it is yet more to learn

I am not saying that doctest is without flaws. I am saying that it is still a good tool, without being perfection.

1 comment:

  1. Lowering the bar? You can write your first test with unittest in about five lines of code.

    I find doctest *fantastic* for maintaining and testing examples in documentation, but deeply flawed as a unit testing tool. I'm not sure that this is a good way to introduce novice programmers to testing...



Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

Blog Archive