RavenDB 单元测试
在我的单元测试中,我将每个测试设置为完全空的 IDocumentSession。我是这样做的:
[SetUp]
public void SetUp()
{
_store = new EmbeddableDocumentStore
{
RunInMemory = true
};
_store.Initialize();
Session = _store.OpenSession();
}
但我认为这可能是我的测试有点慢的原因。我想知道是否有一个简单的命令可以从数据库中删除所有文档。
我想知道的是:我是否可以做到这一点,以及它是否会提高性能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是使用 ravendb 进行单元测试的推荐方法
不推荐用于生产环境,基本上运行在内存模式下
如果您发现这很慢,请尝试进行分析并找出到底是什么导致速度变慢
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
尝试使用 RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true。
Try to use
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
.昂贵的调用是
_store.Initialize()
——您迫使 RavenDb 每次测试都建立一个新数据库。在大多数情况下,每个测试套件运行一个数据库就可以工作。另一种选择是使用 nature 或 RavenDb 的 ID 来命名您的测试。如果真正的问题是重复的关键错误或其他工程问题,那么这非常方便,这样您就不必进行令人讨厌的清理。
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.
我知道这是一个老问题,但从 RavenDB 2.0(尚未稳定)开始,有一个 Raven Test Helper 作为 Nuget 包提供,这在单元测试 RavenDB 时非常有用。
http://ravendb.net/docs/samples/raven-tests/createraventests ?version=2.0
http://nuget.org/packages/RavenDB.Tests.Helpers/2.0.2198-不稳定
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