How can I use OCMock to verify that a method is never called?
Posted
by Justin Voss
on Stack Overflow
See other posts from Stack Overflow
or by Justin Voss
Published on 2010-04-29T16:43:42Z
Indexed on
2010/04/29
16:47 UTC
Read the original article
Hit count: 615
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 thing using Objective-C and OCMock? I've been using the code below, which works but it feels like a hack. I'm hoping there's a better way...
- (void)testSomeMethodIsNeverCalled {
id mock = [OCMockObject mockForClass:[MyObject class]];
[[[mock stub] andCall:@selector(fail) onObject:self] forbiddenMethod];
// more test things here, which hopefully
// never call [mock forbiddenMethod]...
}
- (void)fail {
STFail(@"This method is forbidden!");
}
© Stack Overflow or respective owner