TDD 和 ADO.NET 实体框架 [英] TDD and ADO.NET Entity Framework

查看:20
本文介绍了TDD 和 ADO.NET 实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用 ADO.NET Entity Framework,我发现它适合我正在开发的项目的需求.我也觉得它的非侵入性很酷.

I've been playing with ADO.NET Entity Framework lately, and I find that it suits my needs for a project I'm developing. I also find cool its non-invasive nature.

从现有数据库生成数据模型后,您将面临集成生成模型和业务逻辑的任务.更具体地说,我习惯于集成测试我的类,这些类通过 DAL 接口的模拟/存根与数据存储交互.问题是您无法使用 ADO.NET Entity Framework 执行此操作,因为它生成的实体是没有接口的简单类.

After generating a data model from an existing database you are faced with the task of integrating the generated model and your business logic. More specifically, I'm used to integration-test my classes that interact with the data store via mocks/stubs of the DAL interfaces. The problem is that you cannot do this using the ADO.NET Entity Framework because the entities it generates are simple classes with no interface.

问题是:如何将TDD 方法 应用到使用ADO.NET Entity Framework 的应用程序的开发中?这甚至可能吗,还是我应该迁移到另一个 DAL 生成工具集?

The question is: how do I apply a TDD approach to the development of an application that uses ADO.NET Entity Framework? Is this even possible or should I migrate to another DAL-generation toolset?

推荐答案

对 Entity Framework 的一大批评是它本身就很难测试,例如在 ALT.Net gef 引用的不信任投票.

One of the big critiques against the Entity Framework has been that it is inherently hard to test, for example in the ALT.Net Vote of No Confidence that gef quoted.

这是一篇博文,讨论如何在使用 Entity Framework 时解决这个问题,并能够在不访问数据库的情况下测试您的代码.

Here is a blog post discussing how to get around this, and be able to test your code without hitting the database, when using Entity Framework.

如果可测试性是一个大问题,您可能想看看另一个 ORM 框架,例如 NHibernate,至少在 Entity Framework 2.0 发布之前.

If testability is a big concern, you might want to look at another ORM framework, such as NHibernate, at least until Entity Framework 2.0 is released.

这篇关于TDD 和 ADO.NET 实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆