繁体   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