开发者

TypeMock strange behavior

I found a strange behavior using typemock for unit testing -

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(() =>开发者_C百科 MyClass.foo(2)).WillReturn(-2);
        var p1 = MyClass.foo(1); //p1 = -1
        var p2 = MyClass.foo(1); //p2 = -2 (!!!)
    }
}

in debug mode p1 is -1 and p2 is -2 Is that a bug in typemock or i'm missing something?

Thanks,

Kfir


Isolator by default ignores arguments passed to functions in WhenCalled. In your case you should use WithExactArguments for the expectations to hold:

Isolate.WhenCalled(() => MyClass.foo(2)).WithExactArguments().WillReturn(-2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜