问题
In my unit tests I am setting up each test to have a totally empty IDocumentSession. I do it like this:
[SetUp]
public void SetUp()
{
_store = new EmbeddableDocumentStore
{
RunInMemory = true
};
_store.Initialize();
Session = _store.OpenSession();
}
But I think this might be the reason my tests are a little slow. I was wondering if there is a simple command to delete all documents from the database.
What I want is to know is: if I can do this, and if it would improve performance.
回答1:
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
回答2:
Try to use RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true.
var _store = new EmbeddableDocumentStore()
{
Configuration =
{
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
RunInMemory = true,
}
};
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/7533435/unit-testing-ravendb