Verify with delay, rejects take a lot of time to run tests

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Verify with delay, rejects take a lot of time to run tests

Postby michals » 15 Oct 2014, 10:59

Hi,

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
michals
 

Re: Verify with delay, rejects take a lot of time to run tes

Postby erik » 19 Oct 2014, 16:19

That might be a bug in OCMock. Will look into this.
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany


Return to OCMock