我试图模拟一个方法,它编译时没有错误,但是当我运行测试时会发生奇怪的事情。实际上方法没有嘲笑或者我不明白......(
这是一个代码:
public class Robot
{ ....
public virtual bool range(IObs ob, double range)
{
double dist = ob.distanceSq(this);
if (dist < range)
return true;
else
return false;
}
}
...
public interface IObs
{
double distanceSq(Robot r);
}
...
单元测试:
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
MockRepository mocks = new MockRepository();
IObs obstacleMock = mocks.CreateMock<IObs>();
Robot r = new Robot();
Expect.Call(obstacleMock.distanceSq(r)).IgnoreArguments()
.Constraints(Is.Anything())
.Return(5.5);
Assert.IsTrue(r.range(obstacleMock, 0.5));
}
}
我模拟 distanceSq()。当我调试我的测试时,我看到 ob.distanceSq(this) 是 0.0。(不是 1.5)。
怎么了?