Unit testing and injecting the name of the database instance

Jan 9, 2011 at 9:13 PM

1)  Would it be possible to inject the name of the database instance from a reposiroty. I am having a repository wrap the database instance to which the name of the store is being passed to? This could be useful for unit testing the sterling database so that each database does not overlap

2) What is the best way to set up the sterling database instance for unit tests and also clean up the database during the tests?


Jan 10, 2011 at 1:08 PM

1. The name is a property of the database type and must be present when it is instanced - so basically you have databaseA, databaseB, etc. Your wrapper just needs to map name->type so it can access the correct database.

2. There are dozens of unit tests in the source download, all of them should show examples of setting up and tearing down the database for test.


Jan 10, 2011 at 4:25 PM

1) Ok. If we can have the property being set through a constructor for the instance, we can avoid the overhead of mapping the name to a type and also having multiple types.  In my case, all the types have the same structures in it. Each test creates its own structures and tears them down.  In my case, all my tests funnel through the same factory in my application and as a result end up hitting the same storage. No big deal and can live with it.