Kiwi异步测试引发了EXC_BAD_ACCESS

时间:2013-06-03 10:03:28

标签: objective-c unit-testing asynchronous bdd kiwi

我进行了一次Kiwi测试。一旦进入4次运行,就会引发EXC_BAD_ACCESS异常。可能是什么原因造成的?

它在调用expectFutureValue的第一次异步测试中停止。怎么可能出错? 这是测试:

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_ACCESS异常。可能是什么原因造成的?

更多细节: STACK TRACE State of crash BIG XCODE IMAGE

我还修改了evaluate方法进行零检查:

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

这是结果日志,如果不发生错误: (测试本身失败,但程序运行良好)


测试用例' - [NetworkTest TheCallToTheExternalService_Context_ShouldReturnAnIPAddress]'已启动。 2013-06-04 11:24:24.509 otest [8689:303]主题是NIL

/ Users /.../ KiwiTests / BMNetworkManagerTests.m:81:错误: - [NetworkTest TheCallToTheExternalService_Context_ShouldReturnAnIPAddress]:'对外部服务的调用,上下文,应该返回一个IP地址'[FAILED],预计受到相同的影响“10.1.48.23,194.50.118.230”,得到“10.1.48.252,194.50.118.230”


0 个答案:

没有答案