1
我想测试某个方法被调用以响应NSNotification接收如何验证方法被调用
我已经试过这样:
_sut = mock([EAMainScreenViewController class]);
[_sut view];
[[NSNotificationCenter defaultCenter]postNotificationName:kNotificationPushReceived object:[UIApplication sharedApplication].delegate userInfo:nil];
[verify(_sut) pushReceived:anything()];
而且我_sut viewDidLoad中看起来像这样
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushReceived:) name:kNotificationPushReceived object:[UIApplication sharedApplication].delegate];
}
为什么我的测试不能期待1调用和接收0调用?
顺便说一句,如果我调试 - 调试程序停止在方法
你在哪里测试调用数? – 2015-02-10 14:36:35
验证(_sut)someMethod:应该测试它至少发生一次 – 2015-02-10 14:37:41
你确定它不应该是'verify([_sut pushReceived:anything()]);'而不是? – 2015-02-10 14:47:09