I'm running some unit tests using Castle ActiveRecord that interact with a database. I have a procedure to drop the database (if it exists), then re-create it, before I interact with i开发者_运维技巧t in each test.
If I run one test, this works fine.
If I run multiple tests, the second one fails because it can't drop the database.
Is there some way in Castle ActiveRecord to tell it to shut down and let go of the database?
Instead of dropping the whole database, I recommend dropping and recreating the schema.
To drop the schema: ActiveRecordStarter.DropSchema();
To create the schema: ActiveRecordStarter.CreateSchema();
To reinitialize ActiveRecord: ActiveRecordStarter.ResetInitializationFlag();
then reconfigure it.
See the base AR test class for guidance.
For testing, I recommend taking a look at the new InMemoryTest.
See also: docs for ActiveRecord unit-testing.
精彩评论