我正在尝试编写一个失败的测试,该测试将验证当对象被释放时调用 removeObserver 但是,对于对象不再存在的事实,我如何确定此功能?我会错误地测试这个吗?我正在使用 OCMockito 作为我的模拟框架。
这是我到目前为止所拥有的。
- (void)test_dealloc_NotificationCenterRemoveObserver_ShouldCallRemoveObserver {
self.mockNotificationCenter = mock([NSNotificationCenter class]);
self.sut.defaultNotificationCenter = self.mockNotificationCenter;
self.sut = nil;
[MKTVerify(self.mockNotificationCenter) removeObserver:anything() name:UIContentSizeCategoryDidChangeNotification object:nil];
}