模拟不是接口的类 [英] Mocking classes that aren't interfaces

查看:17
本文介绍了模拟不是接口的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用 C# 编写一些从 providerbase 类继承的提供程序.我发现很难编写使用提供程序的测试,因为大多数模拟框架只允许你模拟一个接口.

I've been writing some providers in c# that inherit from the providerbase class. I've found that it's hard to write tests that use the providers as most mocking frameworks will only allow you to mock an interface.

有什么方法可以模拟对从 providerbase 继承的提供者的调用?

Is there any way to mock a call to a provider that inherits from providerbase?

如果没有,我可以使用一种模式来实现对提供程序的模拟吗?

If not, is there a pattern that I can use to implement mocking of providers?

推荐答案

模拟框架应该能够为你创建一个基于类的模拟对象,只要它有虚拟成员.

Mocking frameworks should be able to create for you a mock object based on a class, as long as it's got virtual members.

您可能还想看看 Typemock

这篇关于模拟不是接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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