0

我正在尝试编写测试用例来测试我的代表。例如,

-(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");
}

此代码运行完美,但问题是当此回调触发时,它不会显示在模拟器中,如 testUserLogin。测试这种情况的标准方法是什么

4

1 回答 1

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;
}
于 2013-03-22T03:58:01.097 回答