How can I use OCMock to verify that a method is never called?

后端 未结 6 2087
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 22:32

At my day job I\'ve been spoiled with Mockito\'s never() verification, which can confirm that a mock method is never called.

Is there some way to accomplish the same thi

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 22:59

    You may also find it necessary to ensure a method is never being called on an object you are partially mocking.

    I created a macro for this:

    #define andDoFail andDo:^(NSInvocation *invocation) { STFail(@"Should not have called this method!"); }
    

    I use it like this:

    [[[_myPartialMock stub] andDoFail] unexpectedMethod];
    

提交回复
热议问题