ios - [[NSRunLoop currentRunLoop] runMode :* beforeDate:*]; 中的 BAD EXC

标签 ios objective-c unit-testing exc-bad-access

我正在尝试通过单元测试对我的应用进行一些压力测试,但遇到了一些问题。下面是我的代码:

    //Stress test api and core data
__block BOOL done = NO;
for (int i = 0; i < 100 ; i++) {
    DLog(@"in here");
    [viewController createList:testList
                       success:^(Lists *list) {
                           DLog(@"in success block : %d", i);
                           STAssertNotNil(list, @"list is not nil");
                           done = (i == 99);
                       }
                       failure:^(NSError *error) {
                           DLog(@"in fail block");
                       }
     ];        
}

@autoreleasepool {

    while (!done) {
        // This executes another run loop.
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }
}

问题是,经过几次迭代后,我在线上得到了一个错误的访问错误

[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];

因为 this post,我已经将 while 循环放在 @autorelease 中.我在项目中使用 ARC,所以我不知道这是否会导致问题......?我需要使用 NSRunLoop 强制单元测试等待 block 完成。

有人遇到过这个问题吗?

最佳答案

在类似的情况下,我采用了不同的方法,但效果很好。我所做的是在主测试中,使用 dispatch_group_async 到普通队列,然后在主测试中等待组完成。这工作得很好,你不会弄乱单元测试的运行循环。

如果出于某种原因上述内容 Not Acceptable ,则尝试不使用任何自动释放池以查看是否可行如果可行,则将其移至 while 中。使用 ARC,对自动释放池的需求大大减少。您也可以使用 Instruments 观察内存使用情况。

关于ios - [[NSRunLoop currentRunLoop] runMode :* beforeDate:*]; 中的 BAD EXC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032356/

相关文章:

ios - Storyboard, self 展示 ViewController,iOS 6,空白屏幕

ios - NSDateFormatter 没有输出我所期望的

ios - 代码片段缺乏理解

iphone - 向使用字母部分的 iPhone 应用程序添加搜索栏?

ios - AFNetworking 在第一次运行时返回 null

c# - 如何对依赖于 App 实例的方法进行单元测试

ios - didSelectRowAt indexPath 播放音频

ios - 使用storeCachedResponse存储在缓存中后,未检索到URLresponse

unit-testing - Grails 与多个服务的集成测试

python - Python 2.7 的突变测试工具