Reputation: 745
I m writing a test case for the following condition
I Have a class (sub class of NSObject) which makes a service call to add a new customer. when it gets a successful response it sends a notification to the view co
Now i want to test that the view controller successfully receives notification and displays the correct alert view.
here is my test case code
-(void) testAlertViewDisplayOnSuccessfullAdditionOfCustomer{
id mockAlertView = [OCMockObject mockForClass:[UIAlertView class]];
(void)[[[mockAlertView expect] andReturn:mockAlertView]
initWithTitle:@"myAppName"
message:@"Submitted Successfully"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:OCMOCK_ANY, nil];
[[mockAlertView expect] show];
[[NSNotificationCenter defaultCenter]postNotificationName:@"notifcationName"
object:nil userInfo:@{@"mykey" : @"Submitted"}];
[mockAlertView verify];
}
But this code isn't working. It crashes at post notification call. Where m i going wrong ?
Upvotes: 0
Views: 309
Reputation: 662
add
[[[mockAlertView stub] andReturn:mockAlertView] alloc];
after creating mock object for your alert view.
Upvotes: 1
Reputation: 1489
Is testAlertViewDisplayOnSuccessfullAdditionOfCustomer getting called? You can check by using a breakpoint.
Perhaps you can use didReceiveLocalNotification in your AppDelegate.m and add your code to the delegate instead?
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
Upvotes: 0