Reputation: 1060
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!
Upvotes: 1
Views: 320
Reputation: 397
Reachability is a toll free bridged class, so partial mocks won't work for your case. From ocmock documentation in http://ocmock.org/features/ :
Note that currently partial mocks cannot be created for instances of toll-free bridged classes, e.g. NSString.
Upvotes: 1