을 ocmock 사용 nsnotificationcenter에 호출 : notificaitonCenterMock 그냥 ID입니다내 기본 모의 수업
- (void)tearDown
{
_mockApplication = nil;
self.observerMock = nil;
self.notificationCenterMock = nil;
}
; 내 테스트에서 그런
나는이 같은 일을 :
이제self.notificationCenterMock = [OCMockObject partialMockForObject:[NSNotificationCenter defaultCenter]];
[(NSNotificationCenter *) [self.notificationCenterMock expect]
removeObserver:self.component
name:UIApplicationDidBecomeActiveNotification
object:nil];
..이 코드를 실행하면 내 단위 테스트는 외관상 하나 개의 실행, 70 또는 65에서 실행됩니다 (예 : 60 (370)의 실패 다음). 몇 가지 단위 테스트는 다음 오류와 함께 실패합니다.
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
테스트가 종료됩니다. 알림 센터를 부분적으로 조롱하면 테스트 스위트를 실행하는 데 문제가 있음을 분명히 알 수 있습니다.
질문은 무엇입니까? 관찰자와 같은 중요한 것들을 설정하고 회귀 증거를 보장하는 것은 매우 좋을 것입니다.
보다 구체적으로 말하면, 어떻게 해드트에서 가짜를 제거 할 수 있습니까? 그것은 nil로 설정하는 것으로 충분하지 않습니다. – Infrid
어디에서 removeObserver를 호출합니까? – psobko