lundi 2 mai 2016

OCMock partial mock tear down issue

I made a partial mock, one test runs as expected but for the second test it calls setUp and teardown back to back without calling the actual test.

- (void)setUp {
  [super setUp];
  _reachability = [Reachability reachabilityForInternetConnection];
  _reachabilityMock = [OCMockObject partialMockForObject:_reachability];
  [[[_reachabilityMock expect] andReturn:_reachabilityMock]
      reachabilityForInternetConnection];
}

- (void)tearDown {
  [_reachabilityMock stopMocking];
  _reachability = nil;
  _reachabilityMock = nil;
  [super tearDown];
}

#pragma mark - Tests

- (void)testWifiReachability {
  [[[self.reachabilityMock stub] andReturnValue:@(ReachableViaWiFi)]
      currentReachabilityStatus];
  XCTAssertTrue([Reachability pckHasWifiConnection]);
}

- (void)testNoReachability {
  [[[self.reachabilityMock stub] andReturnValue:@(NotReachable)]
      currentReachabilityStatus];
  XCTAssertFalse([Reachability pckHasWifiConnection]);
}

I am new to ocmock can someone please help me out ? Thanks!

Aucun commentaire:

Enregistrer un commentaire