Unittests and external data....

Jack Diederich jack at performancedrivers.com
Wed Mar 19 16:12:11 EST 2003


On Wed, Mar 19, 2003 at 08:04:24PM +0000, Mike Meyer wrote:
> 
> For instance, I'm working on a project to interface a data source to
> an SQL database. Doing unit tests properly means I need to have
> multiple different versions of the source around, or I need to modify
> it on the fly. Neither of those is really very practical. Dealing with
> the SQL side of things is possible, so long as I start with an empty
> database for the suite.
> 
> Anyone have any thoughts on how I might better deal with things like
> the source being external to the program?

I use a couple methods that work passably, but of course it is harder
problem that a simple function that does math on the args and returns
an answer.

1 - A dummy SQL object that returns canned answers for a set of inputs,
    which reduces the problem to the simple math example

2 - A test database that is copied (literally copying the files into
    a new MySQL directory).  Then do some operations and do a new SQL
    query that expects some hard coded results (ignoring timestamps).
    Delete the copy of the test database, move on to the next test.

nothing sexy, but good enough.

-jackdied





More information about the Python-list mailing list