david.christian at gmail.com
Tue Apr 7 08:57:27 PDT 2009
On Tue, Apr 7, 2009 at 11:41 AM, Kumar McMillan
<kumar.mcmillan at gmail.com> wrote:
> On Tue, Apr 7, 2009 at 10:08 AM, David Christian
> <david.christian at gmail.com> wrote:
>> Does anyone know of a fixture library that makes it easy to dump
>> database(s) and files and restore them, based on an assigned name?
>> I'd like to be able to say, here are my (postgres|mysql|sqlite)
>> databases for this test and the files I care about are under this
>> directory. Please store them and give them this name.
> So my lesson learned was whenever you need to set up a database and
> insert data for a test you should try to test it another way first.
> If you can make the same test without needing to set up data then you
> just found a better way to test. Mock objects are useful for this but
> are often misunderstood, lots of pitfalls.
> Sometimes you really do need to set up data for a test though. I'm
> just saying it should be a last resort, IMHO.
Databases are useful in integration tests though. At some point you
have to have tests that test the sql. And honestly I'd be just as
happy with a fixture mechanism that let me record the state of a set
of objects to a file as well (pickling them and retrieving them by
name). All those are just versions of the same problem - dump a bunch
of data to a known place, restore it. Simple, really, unless you're
talking about databases or pickling objects.
I would never want to have to maintain db fixture data by hand. IMO
it should be created by a script. In fact most of our fixtures are
created the first time they're run into in the testsuite, and then
used for the remainder of the tests.
>> Anyone have a tool they like for this?
So that sounds like one count of "no, and I wouldn't want it if it existed".
More information about the testing-in-python