0

I'm trying to write testcase for test my delegates. For example,

-(void)testUserLogin{
    loginRequest=[[RTUserLoginRequest alloc]initWithUserNmae:@"1235" password:@"1235"];
    [loginRequest setDelegate:self];
    [loginRequest invoke];


}

-(void)userLoginRequest:(RTUserLoginRequest *)request didSucceed:(BOOL)succeed{

    GHTestLog(@"user login succeed");
}

This code run perfectly but problem is when this callback fired it not display in simulator like testUserLogin. What is the standard method to test this kind of situation

Hasintha Janka
  • 1,608
  • 1
  • 14
  • 27

1 Answers1

0
-(void)testUserPendingRequest{
    userPendingRequest =[[RTCheckUserPendingRequest alloc]initWithUserNmae:@"123"];
    [userPendingRequest setDelegate:self];
    [userPendingRequest invoke];
    [self waitForCompletion:2];
    GHAssertTrue(_isDelegateInvoked, @"check user available invoked");

}

-(void)checkUserPendingRequest:(RTCheckUserPendingRequest *)request isUserPending:(BOOL)pending{
    _isDelegateInvoked=YES;
    if(pending)
        GHTestLog(@"user Pending ");
    else
        GHTestLog(@"User Active");
}

- (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
    NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];

    do {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
        if([timeoutDate timeIntervalSinceNow] < 0.0)
            break;
    } while (!_isDelegateInvoked);

    return _isDelegateInvoked;
}
Hasintha Janka
  • 1,608
  • 1
  • 14
  • 27