How do I do TDD efficiently with NHibernate?

女生的网名这么多〃 提交于 2019-12-04 03:47:10
Tigraine

I am using the Repository Pattern to perform Database operations, and whenever I run my Tests I just run the higher-level tests that simply Mock the Repository (with RhinoMocks).

I have a seperate suite of tests that explicitly tests the Repository layer and the NHibernate mappings. And those usually don't change as much as the business and gui logic above them.

That way I get very fast UnitTests that never hit the DB, and still a well tested DB Layer

Unit testing data access is not possible, but you can integration test it. I create integration test for my data access in a seperate project from my unit tests. I only run the (slow) integration tests when I change something in the repositories, mapping or database schema. Because the integration tests are not mixed with the unit tests, I can still run the unit tests about 100 times a day without getting annoyed.

Min

Have you tried changing some of the defaults in the optional configuration properties? The slowdown is most likely related to certain optimizations nhibernate does with code generation.

http://nhibernate.info/doc/nh/en/index.html#configuration-optional

It seems like an in memory db is going to be the fastest way to test a your data layer. It also seems once you start testing your data layer you're moving a little beyond the realm of a unit test.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!