[Tutor] Test Drive Development, DocTest, UnitTest
Tino Dai
oberoc at gmail.com
Wed Sep 22 13:44:17 CEST 2010
>
> The *primary* purpose of doctests are to be executable examples. When
> you write documentation, including example code is the most natural
> thing in the world. doctest lets you execute those examples, to ensure
> that they work. They're certainly not meant as an exhaustive test of
> every single feature in the program, but as *documentation* that
> happens to also work as tests.
>
> Unit tests can be a little heavyweight, but they're designed for
> exhaustive tests of the *entire* program, not just the parts with
> user-documentation. You should write whitebox tests, not just blackbox
> tests. That means don't just write tests for the published interface,
> but write tests for the unpublished internal details as well.
>
So, the gist is write tests for everything and the "external testing" should
be
handled by unit tests and the "internal testing" by doctests. Is that
correct?
>
> E.g. if your function has special processing to deal with lists of
> strings, then you need a test for input that is a list of strings. But
> it's not necessary to document that fact in the doc string. What do the
> users care that your function calls a special subroutine to deal with
> lists of strings? So it would be inappropriate to draw attention to
> this fact with a doctest.
>
> Doctests don't just execute themselves. If your developers, junior or
> otherwise, don't know about the tests, don't keep the tests up to date,
> and don't run the tests, then it doesn't matter what testing framework
> you use.
>
Point taken.......
>
> Doctests and unittests are complementary. They work well together. In
> fact, the unittest module can even execute doctests.
>
>
This I didn't know this. I will have to do more investigation about this
today. I did find that
the Django doctest's were kind of limiting (at the documentation that I
read). This opens
up more possibilities to unify my tests.
Thanks Steven for the pointers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100922/cf1de564/attachment.html>
More information about the Tutor
mailing list