Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCMock and UIViewController

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?

like image 356
Marc-Alexandre Bérubé Avatar asked Nov 09 '22 01:11

Marc-Alexandre Bérubé


1 Answers

You can stub the method you want to supress by using andDo(nil) as described in 2.10: http://ocmock.org/reference/

like image 127
Erik Doernenburg Avatar answered Nov 15 '22 13:11

Erik Doernenburg