单元测试模拟-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