【问题标题】:How to test the right way the call number of a mocked method in Spring4D 1.2.2?如何正确测试 Spring4D 1.2.2 中模拟方法的调用号?
【发布时间】:2021-12-22 13:37:14
【问题描述】:

我的测试只需要检查给定模拟方法的调用号,没有别的。

被测类和嵌入接口:

type
  IMyInterface = interface ( IInvokable )
    ['{815BD1B0-77CB-435F-B4F3-9936001BA166}']
    procedure bar;
  end;

  TMyClass = class
    private
      fMyInterface : IMyInterface;

    public
      procedure foo;
  end;

procedure TMyClass.foo;
begin
  if ( someCondition ) then
    fMyInterface.bar;
end;

测试用例:

procedure TMyClassUnitTest.foo_bar_NotCalled;
begin
  fMyTestedObject.foo;
  fMyInterfaceMock.Received( 0 ).bar;
end;

跑步者说foo_bar_NotCalled

No assertions were made during the test!

我还应该做什么?我应该调用什么 Assert 方法?

【问题讨论】:

    标签: delphi mocking spring4d dunitx


    【解决方案1】:

    DUnitX 跟踪是否对 Assert 进行了任何调用。 在某些情况下,您只想检查代码是否正常运行而无需进行一些明确的检查。

    在这些情况下,您需要调用Assert.Pass(); 来满足框架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 2012-05-13
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      相关资源
      最近更新 更多