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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值