0

First I mock an object. Then I do something that should make the object's certain method be called. The call is asynchronous.

So what I'd like to verify is: in at most 5 seconds, this method of the mock object should be called.

Any idea?

CarmeloS
  • 7,868
  • 8
  • 56
  • 103

1 Answers1

2

OCMockito doesn't support asynchronous verification (yet). Until it does, I'd recommend using a hand-rolled mock instead, and OCHamcrest's assertWithTimeout.

For example, here's a hand-rolled mock to confirm that fooBar was called:

@interface MockFoo : NSObject
@property (nonatomic, assign) BOOL fooBarWasCalled;
- (void)fooBar;
@end

@implementation MockFoo

- (void)fooBar
{
    self.fooBarWasCalled = YES;
}

@end

Then with OCHamcrest:

assertWithTimeout(5, thatEventually(@(myMock.fooBarWasCalled), isTrue());
Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • Thanks Jon, I've thought about this, but I didn't find a way to turn mockito's verify() into something like a bool value which can be asserted, anything I've been missing? – CarmeloS Nov 28 '15 at 16:40
  • I've added a simple example. – Jon Reid Dec 02 '15 at 03:12