如何关闭或“取消初始化”城堡活动记录?
我正在使用 Castle ActiveRecord 运行一些与数据库交互的单元测试。在每次测试中与数据库交互之前,我有一个过程可以删除数据库(如果存在),然后重新创建它。
如果我运行一个测试,效果很好。
如果我运行多个测试,第二个测试就会失败,因为它无法删除数据库。
Castle ActiveRecord 中是否有某种方法可以告诉它关闭并释放数据库?
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 it 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议删除并重新创建架构,而不是删除整个数据库。
删除架构:
ActiveRecordStarter.DropSchema();
创建架构:
ActiveRecordStarter.CreateSchema();
重新初始化 ActiveRecord:
ActiveRecordStarter.ResetInitializationFlag();< /code> 然后重新配置它。
请参阅 基础 AR 测试类 寻求指导。
为了进行测试,我建议查看新的 内存测试。
另请参阅:ActiveRecord 单元测试文档。
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.