我发现在单元测试中使用类型锁有一个奇怪的行为--
internal class MyClass
{
public static int foo(int param)
{
return param;
}
}
[TestClass]
public class UnitTest1
{
[TestMethod, Isolated]
public void TestMethod1()
{
Isolate.WhenCalled(()=>MyClass.foo(1)).WillReturn(-1);
Isolate.WhenCalled(() => MyClass.foo(2)).WillReturn(-2);
var p1 = MyClass.foo(1); //p1 = -1
var p2 = MyClass.foo(1); //p2 = -2 (!!!)
}
}在调试模式下,p1是-1,p2是-2,是类型锁中的错误,还是我遗漏了什么?
谢谢,
Kfir
发布于 2011-07-10 19:49:25
默认情况下,Isolator忽略传递给WhenCalled中函数的参数。在您的案例中,您应该使用WithExactArguments来表示期望:
Isolate.WhenCalled(() => MyClass.foo(2)).WithExactArguments().WillReturn(-2);https://stackoverflow.com/questions/6640736
复制相似问题