为什么我会选择 Moles 作为我的模拟框架?

发布于 2024-09-05 07:52:23 字数 128 浏览 3 评论 0原文

我一直在研究 ASP.NET 的几个 Mocking 框架,并遇到了 Microsoft Moles。这似乎是 Microsoft 研究团队的一部分,想知道这里是否有人选择 Moles 而不是其他成熟的 Mocking 框架(例如 Moq)。

I've been looking at several Mocking frameworks for ASP.NET and came across Microsoft Moles. This seems to be a part of Microsoft Research team and was wondering If anyone here has selected Moles over other matured Mocking frameworks such as Moq.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心欲静而疯不止 2024-09-12 07:52:23

实际上,我在同一个测试项目中使用 Moq Moles。两者各有长处,我会在适当的时候使用它们。一般来说,我使用 Moq 进行带有验证的标准 AAA 测试,而 Moles 是用于其他不可模拟事物的“大枪”,例如扩展方法调用等。

我喜欢这种安排,因为每个测试都可以像可能的,即使模拟设置可能因测试而异。

I actually use Moq and Moles in the same test project. Both have strengths and I use each where appropriate. Generally, I use Moq for the standard sort of AAA testing with verification, and Moles is the 'big gun' for the otherwise unmockable things, like extension method calls etc.

I like this arrangement, because each test can be as simple and sensible as possible, even though the mocking setup might vary a lot from test to test.

残龙傲雪 2024-09-12 07:52:23

Moles 旨在与 Pex 的白盒分析高效配合。所有其他模拟框架通常会产生大量开销。

Moles 提供了一个简单的价值主张:用委托替换任何 .NET 方法。按照设计,Moles 不像其他框架那样提供任何 API 来表达“验证”。这个决定是否适合您实际上取决于您。

如果您需要处理依赖于硬编码静态方法或具有内部构造函数的密封类型的(遗留)代码,Moles 可以帮助您处理这些情况。

如果您有接口和良好的组件化代码,Moles 还会生成细长的存根(即接口实现),您可以将其与探查器一起使用。

Moles was designed to work efficiently with the white box analysis of Pex. All other mock framework usually incur a lot of overhead.

Moles provides a simple value proposition: replacing any .NET method with a delegate. By design, Moles does not provide any API to express 'verification' as other frameworks do. It is really up to you to decide whether this decision suits your or not.

If you need to deal with (legacy) code that depends on hard-coded static methods or sealed types with internal constructors, Moles can help you deal with these cases.

If you have interfaces and nicely componentized code, Moles also generates slim stubs, i.e. interface implementation, that you can use with the profiler.

方觉久 2024-09-12 07:52:23

Moles 更经常与 TypeMock 进行比较/对比,因为它提供了 Moq 和/或 RhinoMocks 最佳点之外的一系列设施。

在选择时你必须问自己的主要问题是你是否想让你的测试保持相对较低的技术含量,或者参与更高水平的技术欺骗。这很大程度上取决于您正在做的事情 - 您标记了 ASP.NET 而不是 MVC,这表明它可能确实与您相关。

请观看此 Dimecasts.net 视频,了解精彩概述。

Moles is more often compared/contrasted to TypeMock in that it offers a set of facilities outside of Moq and/or RhinoMocks' sweet spot.

The main question you have to ask yourself in choosing is whether you want to keep your testing relatively low-tech or get involved in a higher level of technical trickery. This will largely be dictated by what you're doing - you've tagged ASP.NET and not MVC which suggests that it may indeed be relevant for you.

Have a look at this Dimecasts.net video for a nice overview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文