簡體   English   中英

如何正確測試 Spring4D 1.2.2 中模擬方法的調用號?

[英]How to test the right way the call number of a mocked method in Spring4D 1.2.2?

我的測試只需要檢查給定模擬方法的調用號,僅此而已。

經測試的class和嵌入式接口:

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 方法?

DUnitX 跟蹤是否對 Assert 進行了任何調用。 在某些情況下,您只想檢查代碼是否正確運行而無需進行一些明確的檢查。

在這些情況下,您需要調用Assert.Pass(); 來滿足框架。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM