[英]C# - MOQ: How to add moq on this coding?
I'm a total noob and new on moq. 我是一个菜鸟,新手起订。 I've got a very simple question to ask.
我有一个非常简单的问题要问。
Given the code below, i would like to use moq to test if the return result is as expected. 给定以下代码,我想使用moq来测试返回结果是否符合预期。
public class FrameworkServices : IFrameworkServices
{
public ILoggingService getLogger()
{
return LoggingFactory.getInstance().Create(LoggingEnum.Log4Net);
}
where ILogginService is an interface, LoogingFactory is a class. 其中ILogginService是接口,LoogingFactory是类。
Please share with me on how to moq this. 请与我分享如何起订量。 All kind help are very much appreciated.
非常感谢所有帮助。
You don't need a moq to check if a method returns as expected, just call the method and assert what you need, is a plain standard unit test. 您不需要执行最小起订量即可检查方法是否按预期返回,只需调用该方法并声明所需内容即可,这是一个普通的标准单元测试。 In the example you shown you can mock for example
IFrameworkService
and having getLogger returning a stub logger. 在显示的示例中,您可以模拟
IFrameworkService
并让getLogger返回存根记录器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.