[Tutor] Unit testing

Kent Johnson kent37 at tds.net
Mon Jun 26 20:42:36 CEST 2006


Tino Dai wrote:
> Hey Everybody,
> 
>       First off, I like to thank Kent, Alan, and Danny for their 
> invaluable help. You guys are amazing!

You are welcome!
 
>        I do have some questions about unit testing.
> 
>        I have a part of the code that writes to the filesystem. Is the 
> only way of unit testing that section of code to write a piece of code 
> that will actually go out and test to see if that particular is out 
> there or is there another way?

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.

Kent

PS to the list - I am out of town this week so don't expect my usual volume of postings :-)

-------------- next part --------------
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list