views:

543

answers:

1

I am thinking of using SQLite as an in memory stub for my Oracle database. I can easily direct all my DAL commands to the SQLite, but I am now wondering how I should easily populate the data for each test method.
Should each method begin by creating the needed table(s) and inserting the rows for the specific test? Should I populate in the Fixture SetUp phase the data in the memory? Is there some other way (Like reading it from some file, but discarding the changes so that the next read will be the same)?
Maybe I should just stub the db with a normal stub, and return locally created obejcts when needed (DataSets and DataTables)? I thought about trying this, but this way I will not be testing the actual queries passing along, and I am trying to unit test methods that perform SQL selects. I want to test the syntax and validity of the queries as well.

Any best practices regarding this? Or just good ideas?

+2  A: 

How about just backing up the SQLite-Db-File?

The good thing about SQLite is, that you just can copy the whole db-file as often as you want. You can also have SQL-files to populate some db file with data. I don't understand your problem totally, but with a mixture of db files (as templates) and (optionaly) some SQL-Files to fill tables as needed should suffice for also very difficult testing issues.

The SQL-Files can also easily created by dumping simple files and (optionaly) deleting unwanted entries or adding additional ones.

Juergen
So you think I should keep a file containing my start data, and for each test copy it, and open it with sqlite?I am afraid it will make the tests unreadable, as it won't be obvious why a certain query returns 1 row, or another specific value. The reader would have to check with the input file all the time.Isn't that a problem?
Noam Gal
Hi Noam, of course it all depends on the test environment you have and what exactly your needs are. To store a whole db-file can help to setup a complex test environment without the need to implement it all in code. When you want to have it more readable, you can also create the db file from dump-files everytimes fresh. The dump files are more readable. When you want to have it *all* in code, then it is so -- you will end up all in code.
Juergen