惩戒在C#中的非虚拟方法 [英] Mocking non-virtual methods in C#

查看:161
本文介绍了惩戒在C#中的非虚拟方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要测试一些类,我用嘲笑制作,但我已经看到在C#中的所有免费的嘲弄框架是无法模拟非虚方法(如果它不是在接口)。

I'm trying to test some classes I've made using mocks, but I've seen all free mocking frameworks in c# aren't able to mock non-virtual methods (if it is not in an interface).

但是,有TypeMock谁可以做到这一点,因此它是可能的。任何人都可以显示该怎么办呢?我甚至可以尝试以促进一个开源框架,如果我能得到这个工作。

But, there's TypeMock who can do this, so it is possible. Can anyone show how to do it? I may even try to contribute to an open source framework if I can get this done.

提前

推荐答案

我是从Typemock,我不会解决(为什么人们不希望用最好的工具的工作,虽然这超出了我)太强大了的评论。

I am from Typemock, and I won't address the "Too Powerful" comments (although it's beyond me why people wouldn't want to use the best tool for the job).

下面是Typemock隔离器是如何工作的。你曾经使用过性能分析器?隔离是一个分析器。它挂钩到CLR和测试跑时间内,它的变化的方法。当一个方法获取即时编译,它改变它,所以该方法运行时,执行原代码前,问:我应该运行它原本打算,如果没有,我该怎么办?而且由于这种特定的技术,它可以模拟任何.NET方法和技术。这就是它。

Here's how Typemock Isolator works. Have you ever used a performance profiler? Isolator is a profiler. It hooks into the CLR and within the test run time, it changes methods. When a method gets JITted, it changes it, so when the method runs, before executing the original code, it asks: should I run it as originally intended, and if not, what should I do? And because of this specific technology, it can mock any .Net method and technology. That's it.

当您使用API​​设置行为,回答问题现在变成野趣,并改变在该方法的运行时的行为。很简单,但在幕后这是一个大量的工作:)

When you set a behavior using the API, the answer to the questions now becomes intersting, and changes the behavior at runtime of that method. Simple, but under the covers it's a lot of work:)

隔离带有一个VS外接程序,使内VS无缝地运行测试,并用命令行工具,的MSBuild或恶性任务在构建服务器使用。

Isolator comes with a VS AddIn to make running the tests seamlessly within VS, and with a command line tool and MSBuild or NAnt tasks for usage in a build server.

我很乐意回答你的任何其他问题。

I'll be happy to answer any other questions you may have.

这篇关于惩戒在C#中的非虚拟方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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