我正在为以下条件编写测试用例
我有一个类(NSObject 的子类),它发出服务调用来添加新客户。 当它获得成功响应时,它会向 View 公司发送通知
现在我想测试 View Controller 是否成功接收通知并显示正确的警报 View 。
这是我的测试用例代码
-(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];
}
但是这段代码不起作用。它在发布通知调用时崩溃。我哪里错了?
最佳答案
添加
[[[mockAlertView stub] andReturn:mockAlertView] alloc];
为警报 View 创建模拟对象后。
关于ios - 检查收到的通知是否显示警报 View 的测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34895695/