如何验证 SUT 的方法是否已被调用?
假设我有这个课程,
public class MyClass
{
public void InnerMethod(){}
public void OuterMethod(SomeType sameValue)
{
if(someCondition)
{
InnerMethod();
}
else
{
...
}
}
}
我想检查
[Fact]
public void CanDoSomething()
{
var sut = new MyClass();
sut.OuterMethod(someValue);
//Assert that InnerMethod was called
}
如果 innermethod 属于模拟的对象,我会命名为 innermethod。 ; 。但是,Innermethod是属于SIT本身的具体方法。
如何检查 innermethod 被称为。
感谢您的帮助。
let's say I have this class
public class MyClass
{
public void InnerMethod(){}
public void OuterMethod(SomeType sameValue)
{
if(someCondition)
{
InnerMethod();
}
else
{
...
}
}
}
I want to check that the InnerMethod was called
[Fact]
public void CanDoSomething()
{
var sut = new MyClass();
sut.OuterMethod(someValue);
//Assert that InnerMethod was called
}
If InnerMethod belonged to a mocked object, I would have just called mockObject.Verify(x => x.InnerMethod);
. However, InnerMethod is a concrete method belonging to the sut itself.
How to check that InnerMethod was called.
Thanks for helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论