in my base mock class:
- (void)tearDown
{
_mockApplication = nil;
self.observerMock = nil;
self.notificationCenterMock = nil;
}
where notificaitonCenterMock is just an id;
Then in my tests I do things like this:
self.notificationCenterMock = [OCMockObject partialMockForObject:[NSNotificationCenter defaultCenter]];
[(NSNotificationCenter *) [self.notificationCenterMock expect]
removeObserver:self.component
name:UIApplicationDidBecomeActiveNotification
object:nil];
Now.. if I run this code my unit tests will spuriously fail (i.e. only 60 of 370 will run on one run, 70 or 65 the next). Several of my unit tests will fail with the following errors:
OCPartialMockObject[NSNotificationCenter]: expected method was not invoked: removeObserver:
<VPBCAdComponent-0x17d43e0-384381847.515513: 0x17d43e0> name:@"UIApplicationDidBecomeActiveNotification" object:nil
Unknown.m:0: error: -[VPBCAdComponentTests testCleanUpAfterDisplayingClickthrough_adBrowser_delegateCallback] :
OCPartialMockObject[NSNotificationCenter]: expected method was not invoked: removeObserver:
<VPBCAdComponent-0x17d43e0-384381847.515513: 0x17d43e0> name:@"UIApplicationDidBecomeActiveNotification" object:nil
The tests will then be Terminated. I can clearly see that partially mocking the notification center causes problems for running the test suite.
The question is, what should I do? It'd be extremely nice to ensure that important things such as observers are set, and regression proof..