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.
Mainly Tech projects on Python and Electronic Design Automation.
Thursday, December 04, 2008
Subscribe to:
Post Comments (Atom)
Lowering the bar? You can write your first test with unittest in about five lines of code.
ReplyDeleteI 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...
You have already advanced to thinking on UNIT tests. Good for you.
Delete