我应该考虑选择一个嘲弄框架对于.NET [英] What should I consider when choosing a mocking framework for .Net

查看:184
本文介绍了我应该考虑选择一个嘲弄框架对于.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多嘲讽的框架存在对于.NET他们中的一些已经被取代了别人认为是在各个方面更好。但是这仍然让具有不同的的样式很多嘲弄框架的使用的。

There are lots of mocking frameworks out there for .Net some of them have been superseded by others that are better in everyway. However that still leaves many mocking frameworks that have different styles of usage.

需要学习所有的人都不够好,决定巫婆用的时间是不合理的。我不认为我们还没有达到一个阶段,我们可以谈论的最好的的嘲讽框架。那么,什么问题我应该问有关项目和我来帮助决定最佳的模拟框架在特定情况下使用?

The time it takes to learn all of them well enough to decide witch to use is unreasonable. I don’t believe that we have yet reached a stage that we can talk about the best mocking framework. So what questions should I by asking about the project and myself to help decide on the best mocking framework to use in a given case?

这也将是有益知道你为什么选择目前正在使用的模拟框架,如果你还是很开心与选择。

It would also be useful to know why you choose the mocking framework you are currently using and if you are still happy with that choose.

时尚未有一个有用的词汇比较嘲讽框架的样式时使用?

Is there yet a useful vocabulary to use when comparing the styles of mocking frameworks?

(我有限的这个问题.NET与Java没有任何属性或λEX pression,所以我希望嘲讽框架可以为净,然后java的更好)

(I have limited this question to .Net as Java does not have attributes or lambda expression, so I hope the mocking frameworks can be better for .Net then Jave)

总结至今:

  • 如果您需要模拟静态方法,或 无虚方法,那么唯一的 合理的选择是 TypeMock ,但它不是免费的,不开车你走向一个不错的设计。
  • 犀牛制品是一个非常不错的选择,如果你 在做TDD,.e.g的对象,你 想嘲笑实现接口。在present它似乎是市场领导者
  • 起订量(<一href="http://www.$c$cthinked.com/post/2009/03/13/Beginning-Mocking-With-Moq-3-Part-1.aspx">introduction)如果是,应考虑 使用.NET 3.5起订量的可以的是againing的犀牛制品的新项目
  • If you need to mock static method, or none virtual methods then the only reasonable option is TypeMock, however it is not free and does not drive you towards a good design.
  • Rhino Mocks is a very good option if you are doing TDD, .e.g the objects you wish to mock implement interfaces. At present it seems to be the "market leader"
  • Moq (introduction) should be considered if you are using .NET 3.5 Moq may be againing on Rhino Mocks for new projects

我有什么从这个总结错过了什么?

What have I missed from this summary?

那么是什么驱使犀牛制品和的起订量,如果​​您使用的是.NET 3.5?

So what drives the choose between Rhino Mocks and Moq, if you are using .NET 3.5?


另见:

  • 用什么C#的嘲弄框架?
  • <一个href="http://stackoverflow.com/questions/690769/what-are-the-capabilities-of-moq-and-rhino-mocks">What是起订量和Rhino.mocks的能力?
  • <一个href="http://stackoverflow.com/questions/1718463/what-are-the-real-world-pros-and-cons-of-each-of-the-major-mocking-frameworks">What各主要的嘲弄框架的现实世界的利弊?
  • What c# mocking framework to use?
  • What are the capabilities of Moq and Rhino.mocks?
  • What are the real-world pros and cons of each of the major mocking frameworks?

<一href="http://stackoverflow.com/questions/1267567/what-should-i-consider-when-choosing-a-dependency-injection-framework-for-net">What我应该考虑在选择一个依赖注入框架.NET?的也可能是利益,因为它要求的另一面的质疑。

"What should I consider when choosing a dependency injection framework for .NET?" may also be of interest as it asks the "other side" of the question.

推荐答案

那么,什么问题我应该问有关项目和我来帮助决定最佳的模拟框架在特定情况下使用?

你应该问关于该项目的问题是:这个工程是开发的SOLID原则,还是不行?这是一个具有松耦合和高聚合项目?有良好的面向对象的原则被用来建设该项目?正在使用依赖注入容器?通过合同法对系统是codeD的设计(完全利用接口)?

The questions you should be asking about the project is: Has the project been developed with the SOLID principles, or not? Is this a project that has loose coupling and high cohesion? Have good OO principles been utilized in building the project? Is a Dependency Injection container being utilized? Has the system been coded in a Design by Contract method (utilizing Interfaces thoroughly)?

如果你回答是肯定的这些问题,那么你可以利用模拟框架像RhinoMocks,这就是有些人所说的自以为是的框架。 RhinoMocks,和其他一些嘲讽的框架,对如何系统应设计为使物体被嘲笑很强烈的意见。像RhinoMocks框架期待你的项目被设计以某种方式。嘲讽是肯定有很多与RhinoMocks更容易,当你建立你的$ C C正确的方式$(无密封类,不静,大量使用的接口,虚拟类方法,等等。)

If you answer yes to these questions, then you can utilize a mocking framework like RhinoMocks, which is what some would call an "opinionated" framework. RhinoMocks, and some other mocking frameworks, have very strong opinions about how a system should be designed in order for objects to be mocked. A framework like RhinoMocks expects your project to be designed a certain way. Mocking is certainly a lot easier with RhinoMocks when you've built your code the right way (no sealed classes, no statics, heavy use of interfaces, virtual on class methods, etc.)

如果你没有回答这些问题,或者如果你工作在一个遗留系统有很多高度耦合的类,那么你唯一的选择将是TypeMock,它可以模拟任何事情。

If you answer no to those questions, or if you're working on a legacy system with a lot of highly coupled classes, then your only choice is going to be TypeMock, which can mock just about anything.

这也将是有益知道你为什么选择目前正在使用的模拟框架,如果你还是很开心与选择。

我选择了RhinoMocks,因为在当时(3+年前)是显然是最成熟的模拟框架的大部分功能。我住它,因为它已经在客场,使我的生活变得更轻松(的AutoMocking容器是对效率的一个巨大的一步的到来)演变而来。

I chose RhinoMocks because at the time (3+ years ago) it was clearly the most mature mocking framework with the most features. I've stayed with it because it has evolved in away that makes my life much easier (the advent of the AutoMocking container being a gigantic step toward efficiency).

我喜欢RhinoMocks,比功能集和易用性等,是它引导我走向我的code更好的设计。我不是一个完美的程序员,我要做出的设计错​​误。但是,像RhinoMocks和NHibernate工具,帮助引导我走向一个更好的设计,因为当我犯错误,创造设计不良,这些工具带来痛苦的工作。 NHibernate的,举例来说,是痛苦的用,如果你有一个坏的数据库设计工作。 RhinoMocks是很痛苦的跟,如果你有一个贫穷的一流的设计,在不使用的接口,没有使用IoC的......等工作

What I like about RhinoMocks, other than the feature set and ease of use, is that it guides me toward a better design in my code. I am not a perfect programmer, and I am going to make mistakes in design. But tools like RhinoMocks and NHibernate help guide me toward a better design, because when I do make mistakes and create poor design, these tools become painful to work with. NHibernate, for instance, is painful to work with if you have a bad database design. RhinoMocks is very painful to work with if you have a poor class design, aren't using interfaces, aren't using IoC... etc.

我喜欢RhinoMocks,因为它最终可以帮助我成为一个更好的开发,并不仅仅是因为我在测试我的code,而是因为我塑造我的code - 设计它 - 在一个更好的方式。

I like RhinoMocks because it ultimately helps me be a better developer, and not just because I'm testing my code, but because I'm shaping my code - designing it - in a better manner.

这篇关于我应该考虑选择一个嘲弄框架对于.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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