I am currently researching on how to efficiently add some unit tests to my app's ViewControllers. So far it worked pretty well until I tried to that that a specific view controller presents another one.
I am using OCMock and XCTest. The test is as follows
id partialMock = OCMPartialMock([TestViewController class]);
[partialMock doSomeStuff];
OCMVerify([partialMock presentViewController:[OCMArg any] animated:[OCMArg any] completion:[OCMArg any]]);
As you can see, I only want to verify that presentViewController
was called to the tested view controller inside doSomeStuff
function. Please note that the given example is a simplified version of what I currently have. Main difference being that I am verifying that the argument viewController
is another mocked object.
Problem is since doSomeStuff
method is not stubbed, the call is then forwarded to the real TestViewController
instance, which then calls presentViewController on itself, then not firing the partialMock's verification.
Is there something I am missing? Or is it truly undoable what I am trying to achieve?
You can stub the method you want to supress by using andDo(nil)
as described in 2.10: http://ocmock.org/reference/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With