iosobjective-cocmock

[OCMock][OCMVerify]Why does OCMVerify still pass when I don’t call a method?


for example:

id mockDelegate = OCMProtocolMock(@protocol(managerDelegate));
self.vc.delegate = mockDelegate;
OCMExpect([mockDelegate someMethod:OCMOCK_ANY]);

... Execute some methods to make vc.m respond to someMethod delegate callback...

OCMVerify(mockDelegate);

I implemented the above method and found that even if the class does not respond to the someMethod method, OCMVerify still judges it passed. Why?


Solution

  • For using strict mocks, please have a look at section 7 of the documentation: https://ocmock.org/reference/#strict-mocks-and-expectations

    It's easy to overlook but you have to use OCMVerifyAll for verifying expectations. OCMVerify is used for something else.