I have a IBAction in my view controller which looks like this
-(IBAction)signUpAction:(id)sender
{
AppDelegate *appDel = [[UIApplication sharedApplication]delegate];
//check for internet Connection
if(appDel.isReachable)
{
//Internet Connection available
//perform animation od buttons and imagie view
[self fallDownAnimation];
//after animation perform model segue to corresponding view controller
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.8f target:self selector:@selector(performRegistrationPageSegue) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
else
{
//No internet Connection
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_VIEW_TITLE message:@"No Internet Connection" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
[alert show];
}
}
-(void)performRegistrationPageSegue{
[self performSegueWithIdentifier:@"registerVCSegue" sender:self];
}
I want to write a test case on signUpAction method and verify if the Segue is performed. Since it has a timer the test case i have written is failing. I Need a way to test the following condition
My Current Testcase method is
-(void)testRegisterViewControllerSegueOnAvailableInternetConnection{
AppDelegate *appDel = [[UIApplication sharedApplication]delegate];
appDel.isReachable = YES;
id loginMock = [OCMockObject partialMockForObject:_initialViewControllerToTest];
[[loginMock expect] performSegueWithIdentifier:@"registerVCSegue" sender:[OCMArg any]];
[loginMock performSelectorOnMainThread:@selector(signUpAction:) withObject:_initialViewControllerToTest.signUpButton waitUntilDone:YES];
XCTAssert([loginMock verify],@"Segue to Register Page not Performed on Sign Up Click");
}