design by contract versus doctest
aku
aku at europe.com
Mon Apr 5 14:35:00 EDT 2004
On 2004-04-05, Peter Hansen <peter at engcorp.com> wrote:
> aku wrote:
>
> > On 2004-04-05, Peter Hansen <peter at engcorp.com> wrote:
> >
> >> aku wrote:
> >>
> >>
> >>>Isn't it so, that by applying DBC, a lot of unittests can be
> >>>made redundant?
> >>
> >> How would you propose verifying that your code will work if you
> >> don't run tests before you ship?
> >
> >
> > in debugging mode you obviously have to ensure that the caller
> > makes sure that all preconditions are met...then - by contract -
> > the postconditions are met on returning from the function.
>
> What is "debugging mode"?
>
> You aren't actually talking about _manual_ testing of some
> kind, are you?
no I'm not
> If not, I don't understand how you can be
> talking about automated testing, yet claiming that unit
> tests are redundant. Or are you simply saying that proper
> use of DBC can somewhat _reduce_ the number of unit tests
> you have to write?
yes - the latter. Indeed reduce, not omit. A nr of unittests will
still be necessary to ensure preconditions, but in
the (oversimplified) example I gave (n = 1), the test
"if n < 0: ..." isn't necessary anymore and certainly not *in*
the called function itself.
The "downside" with DBC I see is: when the caller *cannot*
ensure a precondition, then the behavior in the called
function becomes unpredictable.
(In which case I ask how do you propose
> to verify that your precondition contracts are written properly?)
>
> -Peter
More information about the Python-list
mailing list