使用 Typemock 断言一个方法被调用了 x 次
Asserting that a method was called x times with exact arguments using Typemock
我有一个带有此签名的方法:
public static void foo(int x, int y)
{
//do something...
}
我想验证此方法在 x = 5
和 y = 10
时被调用了 2 次。我怎样才能使用 Typemock 做到这一点?
我试了一下,得出以下结论:
鉴于 class:
public class Bar
{
public static void Foo(int x, int y)
{
//do something...
Debug.WriteLine($"Method called with {x} {y}");
}
}
您的测试将如下所示:
[TestClass]
public class Test
{
[TestMethod]
public void TestMethod()
{
var callCount = 0;
Isolate.WhenCalled(() => Bar.Foo(2, 10))
.WithExactArguments()
.DoInstead(context =>
{
callCount++;
context.WillCallOriginal();
});
Bar.Foo(2, 6);
Bar.Foo(2, 10);
Bar.Foo(2, 10);
Assert.AreEqual(2, callCount);
}
}
我有一个带有此签名的方法:
public static void foo(int x, int y)
{
//do something...
}
我想验证此方法在 x = 5
和 y = 10
时被调用了 2 次。我怎样才能使用 Typemock 做到这一点?
我试了一下,得出以下结论:
鉴于 class:
public class Bar
{
public static void Foo(int x, int y)
{
//do something...
Debug.WriteLine($"Method called with {x} {y}");
}
}
您的测试将如下所示:
[TestClass]
public class Test
{
[TestMethod]
public void TestMethod()
{
var callCount = 0;
Isolate.WhenCalled(() => Bar.Foo(2, 10))
.WithExactArguments()
.DoInstead(context =>
{
callCount++;
context.WillCallOriginal();
});
Bar.Foo(2, 6);
Bar.Foo(2, 10);
Bar.Foo(2, 10);
Assert.AreEqual(2, callCount);
}
}