views:

29

answers:

2

Hi,

Can you recommend me a way or tell me the most common practice to create a sample portion of a data-base as an xml file so that I can use it from my unit tests without worrying about Db state to be persistent?

Is there any frame work to overcome such a scenerio including the functionality that after each test I can get back to the previous state of the XML file which will be the sample data obtained from the Db?

Thanks

A: 

If your test hits either a database or an XML it isn't a Unit Test it is an integration test.

If you are looking to do true unit tests google for the Object Mother pattern.

If you are looking to do integration tests that hit the database you can use Transactions to ensure that database changes are not persisted outside the scope of the test.

I hope this helps.

Burt
+2  A: 

Look at the NDbUnit framework. It's designed for exactly that test setup - having a database filled by data from an XML file.

Tip:
Use it in combination with an in-memory database system such as System.Data.SQLite and you get rid of the necessity to hit a server machine, thus making your database-involving tests (which aren't - strictly speaking - unit tests, but integration tests) more reliable and lightning-fast.

HTH!
Thomas

Thomas Weller