vendredi 27 février 2015

How to unit test removeObserver in dealloc

I am trying to write a failing test that would verify removeObserver is called when an object is dealloc'ed however, do to the fact that the object is no longer around, how do I determine this functionality? Am I going about testing this incorrectly? I am using OCMockito for my mocking framework.


Here is what I have so far.



- (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];
}

Aucun commentaire:

Enregistrer un commentaire