My project use OCMock, OHHTTPStubs and XCTest.
I try to test SDK (SDK implemented by my), so i stub Http response/requests and add some expectation on callback methods. Each unit tests have some expectations that delegate methods will be called properly and after setting all expectations i included rejects for each delegate method to be sure that only specified methods will be called and nothing more.
All tests pass successfully but it take a lot of time to run everything. But what i saw, when i remove those rejects all tests run 3 times faster.
After some debuging i check the implementation of OCMock library method:
- Code: Select all
- (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location
{
NSTimeInterval step = 0.01;
while(delay > 0)
{
if([expectations count] == 0)
break;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:step]];
delay -= step;
step *= 2;
}
[self verifyAtLocation:location];
}
And where rejects are registered the "expectations" variable always contains those rejcts.
Has anybody the same problem ?
Maybe i do somethig wrong ?
Example of my unit test:
- Code: Select all
// stub http
... here are some http stubs...
// expect
[[self.mockDelegate expect] didSomethigHappend:[OCMArg checkWithBlock:^BOOL(id obj) {
BOOL result = NO;
// testing parameter object
if(result) {
// call next method on SDK
[self.objectToTest nextMethod];
}
return result;
}] withError:[OCMArg isNil]];
// reject any other call:
[[self.mockDelegate reject] didSomethigHappend:[OCMArg any] withError:[OCMArg any]];
[[self.mockDelegate reject] dodSomethig2:[OCMArg any] withError:[OCMArg any]];
[[self.mockDelegate reject] dodSomethig3:[OCMArg any] withError:[OCMArg any]];
[super.objectToTest doSomethigWithDelegate:super.mockDelegate]; // run
[super.mockDelegate verifyWithDelay:3]; // verify