Objective c Kiwi异步测试引发EXC\u错误访问
我做了猕猴桃测试。每4次运行一次,就会引发EXC_BAD_访问异常。这可能是什么原因 它在第一个异步测试的中间停止,调用代码>期望值> /代码>调用。会出什么问题? 这就是测试:Objective c Kiwi异步测试引发EXC\u错误访问,objective-c,unit-testing,asynchronous,bdd,kiwi,Objective C,Unit Testing,Asynchronous,Bdd,Kiwi,我做了猕猴桃测试。每4次运行一次,就会引发EXC_BAD_访问异常。这可能是什么原因 它在第一个异步测试的中间停止,调用代码>期望值> /代码>调用。会出什么问题? 这就是测试: SPEC_BEGIN(NetworkTest) describe(@"The call to the external service", ^{ context(@"context", ^{ __block id origin = nil; __block int x = 0; __blo
SPEC_BEGIN(NetworkTest)
describe(@"The call to the external service", ^{
context(@"context", ^{
__block id origin = nil;
__block int x = 0;
__block AFJSONRequestOperation *operation;
beforeEach(^{
/*
[OHHTTPStubs addRequestHandler:^OHHTTPStubsResponse*(NSURLRequest *request, BOOL onlyCheck){
return [OHHTTPStubsResponse responseWithFile:@"test.json" contentType:@"text/json" responseTime:1.0];
}];
*/
origin = nil;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://httpbin.org/ip"]];
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
origin = [JSON valueForKeyPath:@"origin"];
x = 1;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
// no action
origin = @"no";
}];
[operation start];
});
afterEach(^{
origin = @"";
operation = nil;
});
it(@"should be not nil", ^{
[[expectFutureValue(origin) shouldEventuallyBeforeTimingOutAfter(3.0)] shouldNotBeNil];
});
it(@"should set x to 1", ^{
[[expectFutureValue(theValue(x)) shouldEventuallyBeforeTimingOutAfter(3.0)] equal:theValue(1)];
});
it(@"should return an IP address", ^{
[[expectFutureValue(origin) shouldEventuallyBeforeTimingOutAfter(3.0)] equal:@"10.1.48.223, 194.50.118.230" ];
});
});
});
SPEC_END
每4次运行一次,就会引发EXC_BAD_访问异常。这可能是什么原因
更多详情:
我还修改了用于零检查的评估方法:
- (BOOL)evaluate
{
if (self.subject == nil) {
NSLog(@"The subject is NIL");
}
/** handle this as a special case; KWValue supports NSNumber equality but not vice-versa **/
if ([self.subject isKindOfClass:[NSNumber class]] && [self.otherSubject isKindOfClass:[KWValue class]]) {
return [self.otherSubject isEqual:self.subject];
}
return [self.subject isEqual:self.otherSubject];
}
这是未发生故障时的结果日志:
(测试本身失败,但程序运行良好)
测试用例“-[networktestthecalltotheexternalservice\u Context\u shouldlreturnanipaddress]”已启动。
[参考译文]受试者为零
/Users/../KiwiTests/BMNetworkManagerTests.m:81:错误:-[NetworkTest调用外部服务\u Context\u shouldneturnanipaddress]:“调用外部服务,Context,应该返回一个IP地址”[失败],预期等于“10.1.48.23194.50.118.230”,获得“10.1.48.252194.50.118.230”
你有堆叠痕迹,还是猕猴桃把它弄脏了?是的,我有。给你,我不能用你的代码复制这个。您是否能够在KWEqualMatcher
的evaluate
方法中设置断点,以便更好地了解故障的确切位置?另外,你是否尝试过干净的构建、更新猕猴桃椰子荚等?我已经为这个问题添加了更多细节。希望能有帮助。