Search code examples
iphoneobjective-cunit-testingocmock

How to verify number of method calls using OCMock


Is there a way to verify that a method has been called 'x' amount of times?


Solution

  • Looking at the test file for OCMock, it seems that you need to have the same number of expects as you have calls. So if you call someMethod three times, you need to do...

    [[mock expect] someMethod];
    [[mock expect] someMethod];
    [[mock expect] someMethod];
    
    ...test code...
    
    [mock verify];
    

    This seems ugly though, maybe you can put them in a loop?