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

后端 未结 6 2088
佛祖请我去吃肉
佛祖请我去吃肉 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 23:14

    As far as I know OCMock will fail automatically when you call verify and methods that have not been recorded were called. A mock that wouldn't complain if unexpected methods were called is called a "nice mock".

    - (void)testSomeMethodIsNeverCalled {
        id mock = [OCMockObject mockForClass:[MyObject class]];
    
        [mock forbiddenMethod];
        [mock verify]; //should fail
    }
    

提交回复
热议问题