OCUnit test for protocols/callbacks/delegate in Objective-C

后端 未结 2 1621
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 15:02

Using OCUnit, is there a way to test delegate protocols?

I\'m trying this, which doesn\'t work.

-(void) testSomeObjDelegate {
  SomeObj obj = [[SomeO         


        
2条回答
  •  情歌与酒
    2020-12-07 15:52

    Please, review Unit Testing Asynchronous Network Access. I think can help you. In short what it does is:

    Add the following method which will take care of the synchronization between the unit test code and the asynchronous code under test:

    - (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
        NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
    
        do {
            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
            if([timeoutDate timeIntervalSinceNow] < 0.0)
                break;
        } while (!done);
    
        return done;
    }
    

提交回复
热议问题