我刚开始使用moq对象进行单元测试,我不确定我是否正确执行此操作,请帮助!无法在单元测试中使用moq
Public Class Mrr: IMrr
{
public int Delete(double obj)
{
int rtcode = somefunction(obj);// retreiving some code from function
int DeleteMrr= DeleteFunction(rtcode); // delete function executes here
return 0;
}
}
这里是接口
public interface IMrr
{
int Delete(double obj);
}
和我的测试方法是这样的。
[TestMethod()]
public void RetrieveSaveDeleteMRR()
{
var FakeObject = new Moq.Mock<IMrr>();
FakeObject.Setup(x => x.Delete(It.IsAny<int>())).Returns(0);
var Res = FakeObject.Object.Delete(10);
}
这不是要去执行该方法的实际功能,它假设去那里的方法或不去。我不确定。
HI, 我编辑我的代码,你可以告诉我你是什么人都在谈论这里真正的依赖? –
请检查Moq的基本教程 - http://deanhume.com/home/blogpost/basic-introduction-to-writing-unit-tests-with-moq/16 – CodeFuller
是实现的必要接口吗? –