Data-driven testing

Peter Hansen peter at
Thu Apr 24 17:39:32 CEST 2003

Alex Martelli wrote:
> Peter Hansen wrote:
> > Aahz wrote:
> >>
> >> Which brings up the question: do the unit-testers here write tests for
> >> throwaway scripts?
>     ...
> > Basically, with a literally throwaway script, you do lose much of
> > the business value of the tests, so as far as I can see you write
> > them only if they truly help you write the code properly, which
> > should once you're proficient at TDD and then only sometimes, since
> > you're a very experienced programmer.  Otherwise, and certainly in some
> > cases no matter who you are, they really would be a waste of time.
> > IMHO.  Except maybe to help you develop the habits.   _Four_ reasons...
> Oh come on -- we all know that some "throw-away" scripts happen
> to NOT get thrown away, but rather lie around and get reused and
> tweaked and grown and...  It's hard to quantify HOW MANY such
> "throw-away" scripts are in fact thrown away, and how many end
> up getting kept (and reused and grown) instead -- guess it depends
> on how good one is at planning / forecasting -- but as for me,
> I would paraphrase Brooks' MMM Chapter 11's famous title:
>         Plan NOT to throw one away -- you won't, anyway.

I could have said that, but I know Aahz knows when something is really
throwaway, and there are such things, so I thought I'd try answering
the question directly for a change.  ;-)  And I did emphasize that this 
was for _literally_ throwaway scripts, which do exist.  If nothing else,
you could call it a spike solution which is expected to be used, once
only, then tossed.  If it turns out it's got to be used again, then it 
should be re-written anyway so it's not a serious problem that it lacks 

For me, if the script has any identifiable subroutines, let's say as
an example a routine which produces a filtered list of files with a
particular extension and which have been written in the last day, then
I would drive that with tests, even for a throwaway.  As Timothy Grant
pointed out, you generally want to know that even your throwaway scripts
work properly.  I'm just less anal about testing the ones I think are
throwaway than the ones I "know" are not.  If I'm wrong... no big deal:
I rewrite as a real script with proper tests.  Since the script was 
only twenty or thirty lines of code (any more and it could not possibly
be throwaway, right?) it isn't really a big deal.


More information about the Python-list mailing list