Search code examples
iosobjective-cunit-testingmockingocmock

Using primitive type parameter in OCMVerify


I am using OCMock as a mocking framework in my iOS project. When I try to use OCVerify functionality to test that a certain method is invoked, I came across a problem of passing primitive types as parameters. Here is an example to show problem:

1-) Cases successfully verify invocation when no parameter or an object parameter.

OCMVerify([mockedClass methodToCall])
OCMVerify([mockedClass methodWithObjectParameter:[OCMArg any]);

2-) When I want to verify a method that takes an int as a parameter:

OCMVerify([mockedClass methodWithIntParameter:[OCMArg any]);

In this case [OCMArg any] doesn't act like as expected. It returns an actual integer and that causes a mismatch of parameter values. In reality I do not care if that integer value is correct or not. My only consideration is if the method is called with any integer regardless of its value.

I want to know that is there a way to have exact same effect of [OCMArg any] has on objects when using primitive types as parameters?


Solution

  • Please see section 4 in the documentation.