What is the difference between mock.verify and mock.verifyAll in Delphi Mocks? Does it verify expectations of other mocks as well? I want to verify all expectations of all my mocks created for the current unit test.
Asked
Active
Viewed 192 times
1 Answers
3
You can tell a mock of an interface that it also can mock other interfaces. This is useful if the interface you mock is asked via Supports for another interface.
Verify
checks if the expectations of the directly mocked type while VerifyAll
also checks the expectations of the other interfaces.
Example
var
foo: TMock<IFoo>;
begin
foo := TMock<IFoo>.Create;
foo.Implements<IBar>;
foo.Setup.Expect.Once.When.DoThis;
foo.Setup<IBar>.Expect.Once.When.DoThat;
// pass mock to tested component which
// calls DoThis and Supports(IBar) and calls DoThat
foo.Verify; // checks if DoThis was called once
foo.VerifyAll; // also checks if DoThat on the mock as IBar was called.
end;

Stefan Glienke
- 20,860
- 2
- 48
- 102
-
So if I have many mocks I have to verify them one by one? There is no way to do that by one shot? – The Bitman Mar 17 '17 at 22:49
-
Personally I think that Verify/VerifyAll is an anti pattern and others do so as well - http://russellallen.info/post/2011/04/15/Moq-asserts-Verify()-vs-VerifyAll().aspx I also think that the Moq author (which Delphi Mocks was inspired by) changed this to rather using dynamic mocks and then do the verification after with specifying what calls were expected (see https://github.com/moq/moq4/wiki/Quickstart#verification) - not sure if Delphi Mocks can do something similar. – Stefan Glienke Mar 19 '17 at 02:23