[Tutor] Unit testing

Tino Dai tinoloc at gmail.com
Mon Jun 26 21:50:36 CEST 2006


> I often write unit tests that do this. In my opinion it is simple and
> straightforward and effective. Some purists will insist that a unit test
> shouldn't write the file system or touch a database or use any other
> external resource, but I think that is silly - if the job of a bit of code
> is to write a file or interact with the database, then the simplest way to
> test it is to check the file or database. As long as the tests run fast
> enough it's OK. (For me, a unit test on a single module should ideally run
> in well under a second.)
>
> Alternately you can use StringIO or other substitutes for files in your
> tests. But somewhere in your test system you probably want to make sure the
> actual file is there on disk, whether it is in a unit test or acceptance
> test.


Ok, that leads me to my next question.  Currently, I have a class that I
want to unit test, but it contains a semaphore from another class. Now, I
could make the semaphore a global variable, or I bring in the other class.
One violates "good" programming principles and the other violates the unit
testing principles. Is there another way?

-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060626/bf127497/attachment.htm 


More information about the Tutor mailing list