[英]How to test the right way the call number of a mocked method in Spring4D 1.2.2?
My test just has to check the call number of a given mocked method, nothing else.我的测试只需要检查给定模拟方法的调用号,仅此而已。
The tested class and the embedded interface:经测试的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;
The test case:测试用例:
procedure TMyClassUnitTest.foo_bar_NotCalled;
begin
fMyTestedObject.foo;
fMyInterfaceMock.Received( 0 ).bar;
end;
The runner says for foo_bar_NotCalled
:跑步者对
foo_bar_NotCalled
说:
No assertions were made during the test!
What else should I do?我还应该做什么? What method of the Assert should I call?
我应该调用什么 Assert 方法?
DUnitX tracks if any call to Assert was made. DUnitX 跟踪是否对 Assert 进行了任何调用。 In certain cases you just want to check if the code just ran properly without some explicit checks.
在某些情况下,您只想检查代码是否正确运行而无需进行一些明确的检查。
In these cases you need to call Assert.Pass();
在这些情况下,您需要调用
Assert.Pass();
to satisfy the framework.来满足框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.