gpt4 book ai didi

ios - OCMock 部分模拟拆卸问题

转载 作者:行者123 更新时间:2023-11-29 12:01:03 26 4
gpt4 key购买 nike

我做了一个部分模拟,一个测试按预期运行,但对于第二个测试,它连续调用 setUp 和 teardown 而没有调用实际测试。

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

我是 ocmock 的新手,有人可以帮助我吗?谢谢!

最佳答案

Reachability 是一门免费桥接类(class),因此部分模拟不适用于您的情况。来自 http://ocmock.org/features/ 中的 ocmock 文档:

Note that currently partial mocks cannot be created for instances of toll-free bridged classes, e.g. NSString.

关于ios - OCMock 部分模拟拆卸问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36987844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com