我正在尝试为测试我的代表编写测试用例。例如,
-(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。测试这种情况的标准方法是什么?
答案 0 :(得分: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;
}