zoukankan      html  css  js  c++  java
  • 单元测试模拟-moq

    1、moq 支持 net core

    2、moq 通过一个接口类型 可以产生一个新的类

    3、举例

    //define interface to be mocked
    
            public interface ITest
            {
    
                bool DoSomething(string actionname);
    
            }
    
            //define the test method
    
            [TestMethod]
    
            public void Test_Interface_IFake()
            {
    
                //创建一个模拟对象 实现 itest
    
                var mo = new Mock<ITest>();
    
                //安装模拟对象,并设置输入ping的时候 返回真
    
                mo.Setup(foo => foo.DoSomething("Ping"))
    
                .Returns(true);
    
                //断言
    
                Assert.AreEqual(true, mo.Object.DoSomething("Ping"));
            }

    IT   详细X
    基本翻译
    abbr. information technology 信息技术
    网络释义
    ITest: 接口
    schimmer Itest: 基础泪液分泌试验
  • 相关阅读:
    可执行
    创建
    可能的加分项
    给老师的建议
    周总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
  • 原文地址:https://www.cnblogs.com/zxs-onestar/p/8427392.html
Copyright © 2011-2022 走看看