如何验证 SUT 的方法是否已被调用?

发布于 2025-01-17 18:35:16 字数 623 浏览 4 评论 0原文

假设我有这个课程,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文