Xcode 7魔法记录单元测试失败

jos*_*ons 13 core-data objective-c ios magicalrecord

从Xcode 6.4升级到Xcode 7(现在是7.0.1)后,我的项目在启动单元测试时崩溃了.我的iOS项目正在使用魔法记录,应用程序在此断言崩溃:

    + (NSManagedObjectContext *) MR_defaultContext
{
    @synchronized(self) {
        NSAssert(MagicalRecordDefaultContext != nil, @"Default context is nil! Did you forget to initialize the Core Data Stack?");
        return MagicalRecordDefaultContext;
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经注释掉了我以前的所有测试,这两个测试都显示了相同的行为:

#import <XCTest/XCTest.h>

@interface BadTests : XCTestCase

@end

@implementation BadTests

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)testSanity {
    XCTAssert(1 == 1);
}

@end
Run Code Online (Sandbox Code Playgroud)

#import <XCTest/XCTest.h>
#import <MagicalRecord/MagicalRecord.h>

@interface BadTests : XCTestCase

@end

@implementation BadTests

- (void)setUp {
    [super setUp];
    NSLog(@"*** USING IN MEMORY STORE ***");
    [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelDebug];
    [MagicalRecord setupCoreDataStackWithInMemoryStore];
}

- (void)tearDown {
    [MagicalRecord cleanUp];
    [super tearDown];
}

- (void)testSanity {
    XCTAssert(1 == 1);
}

@end
Run Code Online (Sandbox Code Playgroud)

使用相同的测试恢复到Xcode 6可以解决问题.

jos*_*ons 1

最终通过调整我的 Podfile 解决了问题:

link_with 'TestApp', 'TestAppTests', 'TestAppUITests'

platform :iOS, '8.1'

target 'TestApp' do
     pod 'MagicalRecord'
end

target 'TestApp' do
     pod 'OHHTTPStubs'
end
Run Code Online (Sandbox Code Playgroud)

以前我的 pod 文件看起来像这样:

platform :iOS, '8.1'
pod 'MagicalRecord'
pod 'OHHTTPStubs'
Run Code Online (Sandbox Code Playgroud)