C# 的非接口依赖模拟框架

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

问题描述

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

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 classobject 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.

推荐答案

微软研究院开发了 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# 的非接口依赖模拟框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)