Entity Framework 4 CTP 5 POCO - 如何对我的存储库进行单元测试
这是另一个问题的第二部分Entity Framework 4 CTP 4 / CTP 5 通用存储库模式和可单元测试),我在其中询问如何使用 EF 4 POCO 实现通用存储库模式。现在我的存储库正在运行,我想知道如何对我的存储库进行单元测试(TDD 或 BDD)。
谢谢大家。
This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD).
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,我写了一些关于使用 SpecFlow 执行此操作的博客文章。但当事情变得复杂时,那就是一场灾难。
我尝试实现一个测试存储库,但这也是一场灾难。尝试复制数据上下文的工作方式并不是一个明智的想法。
但你会从错误中吸取教训,并一路享受乐趣。我学到的是使用轻量级或内存数据库(SQLite)。
因此,如果您可以使用 EF Code First 来使用 SQLite 数据库,我肯定会说使用 SQLite 数据库。我无法做到这一点,所以我选择了 SQL CE 精简版。即使在测试中,它的运行速度也快得惊人。
您可能了解这篇博文的所有内容,但请重新检查步骤 4。 http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
所以本质上,我在最近的项目中所做的就是拥有一个单独的数据库 SQL CE 4.0 紧凑版来进行测试。超级快而且没有抱怨。
Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex.
I tried to implement a testing repository which was also a disaster. Trying to replicate how the data context work is not a smart idea.
But you learn from your mistakes and have fun along the way. What I learnt was to use a light-weight or in-memory database (SQLite).
So I would definitely say to use a SQLite database if you can get it working with EF Code First. I wasn't able to do this, so I went with a SQL CE compact edition. It runs amazingly quick, even in testing.
You probably know all about this blog post, but re-check step 4. http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
So in essence, all I did on my most recent project was to have a separate database SQL CE 4.0 compact edition for testing. Super quick and no complaints.