Was Re: "stuff", a general request for help, now 'Ideas on correct use of PyUnit in Unit Tests'

Shae Erisson shapr at uab.edu
Fri May 12 14:41:55 CEST 2000

Glyph Lefkowitz wrote:

> As long as I'm encouraging people to download this thing, too; I am
> getting started with PyUnit and regression testing ... but my tests
> seem really random and arbitrary.  Much appreciated would also be
> comments on the style / structure of said tests (in the regr/
> directory) and pointers to better ones.  I've read about JUnit and
> PyUnit, but there doesn't seem to be much in the way of a description
> of what makes a good test.
> Right now, writing tests takes 2x as long as writing the code
> initially, and there have been more bugs in the tests than in the code
> itself.  I know that these can be a real resource for me, but I'm not
> quite sure how.

This is still a half done thought.. but I have been thinking about this

I'm slowly writing a Python Refactoring Browser[1], and the thesis that
is the primary documentation for the process of design and
implementation of the first Refactoring Browser written in Smalltalk,
mentions several things:

refactorings are only 90% mathematically provably correct, so unit tests
are used to assure that you have the same behaviour after a refactoring
that you had before.
that implies that:
unit tests should work the same before and after a refactoring.
the thesis also says:
refactoring cannot preserve _all_ code functionality, any refactoring
_will_ change the code.

When I first started writing unit tests I had a very fine granularity, I
would test each method with lots of input. That doesn't work because I'm
not testing the 'behaviour,' I'm testing the code...

If you ascribe to the Extreme Programming methodology, UnitTests come
from User Stories. User Stories are 'functional requirements' that the
client has given you. Therefore, I think UnitTests should not test the
code, they should test that the functional requirements are passed.

I can't think of any great examples at this moment, but I hope someone
else can contribute some.

As the issue of 'how to correctly construct unit tests' is alternately
clear and confused to me, I would _really_ like to get more feedback
from other people.


[1] http://bicyclerepair.sourceforge.net - no code nor any kind of
homepage is up yet... but progress has been made.

ps. If you would like pointers to any of the above mentioned info, I can
furnish them.
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
      "Cry Haddock and let slip the Frogs of War!"

More information about the Python-list mailing list