我是 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# 的非接口依赖模拟框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超
使用电子邮件地址和应用程序密码从 oauth2/tokenGetting access token using email address and app password from oauth2/token(使用电子邮件地址和应用程序密码从 oauth2/token 获取访问令
新的 Azure AD 应用程序在通过管理门户更新之前无New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 应用程序在通过管理门户更新之前无法运行