Unit Testing RavenDB

我是研究僧i 提交于 2019-11-29 02:52:20

This is the recommended approach for unit testing with ravendb The not recommended for production basically runs in the in memory mode If you find this to be slow, try profiling and figuring out what exactly is slowing things down

Daniel Lang

Try to use RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true.

        var _store = new EmbeddableDocumentStore()
        {
            Configuration =
                {
                    RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                    RunInMemory = true,
                }
        };

The expensive call there is the _store.Initialize() -- you are forcing RavenDb to stand up a new database every test. In most cases a single database per test suite run will work.

Another option would be to use the nature or RavenDb's IDs to namespace your tests. This is pretty handy if the real issue is duplicate key errors and otherwise engineering things so you don't have a nasty cleanup.

I know this is an old question but as of RavenDB 2.0 (not yet stable) there is a Raven Test Helper available as a Nuget package which is really useful when it comes to unit test RavenDB.

http://ravendb.net/docs/samples/raven-tests/createraventests?version=2.0

http://nuget.org/packages/RavenDB.Tests.Helpers/2.0.2198-Unstable

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