C#的非依赖于接口的模拟框架 [英] Non Interface dependent Mocking Frameworks for C#

查看:72
本文介绍了C#的非依赖于接口的模拟框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是模拟的新手,所以我在这里可能完全错了,但是我相信大多数模拟框架都依赖于接口.不幸的是,我们的大多数代码都没有使用接口.现在有一天,我看到了Java中的Mocking框架,该框架重现了class \ object的字节码,以便不调用其内部方法,但是您仍然可以测试它是否在调用这些方法.

I am new to mocking so I might have it totally wrong here but I believe that most mocking frameworks are interface dependent. Unfortunately most of our code is not using an interface. Now the other day I saw a Mocking framework in Java that reproduced the byte code of a class\object as to not call its internal methods but you could still test that it WAS calling these methods.

我的问题是:.Net是否有任何可以做类似事情的模拟框架?我正在寻找免费的东西,并且我不希望某些东西需要方法是虚拟的或抽象的.

My question is: does .Net have any mocking frameworks that can do a similar thing? I am looking for something free and I don't want something that requires methods to be virtual or abstract.

推荐答案

Microsoft Research开发了 Moles 为此,它是Pex的一部分,但可以独立安装.而且是免费的.网站上有很好的介绍性文章(pdf),其中解释了如何模拟静态方法.他们需要一些时间才能找到所需的内容(第16页,任务3).

Microsoft Research has developed Moles for this, which is a part of Pex but can be installed independently. And it's free. There's a good introductory article (pdf) on the website that explains how to mock a static method. It takes some time before they get to the stuff you want (page 16, Task 3).

此处此处(频道9)您可以找到有关如何对DateTime.Now进行存根的示例.使用Moles,您可以模拟任何想要的东西.

Here and here (Channel 9) you can find an example on how to stub DateTime.Now. Using Moles, you can mock anything you want.

这篇关于C#的非依赖于接口的模拟框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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