Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 Magical Record Unit Tests Fail

After upgrading from Xcode 6.4 to Xcode 7 (and now 7.0.1) my project crashes when starting unit tests. My iOS project is using Magical Record and the app crashes at this assertion:

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

I've commented out all of my previous tests, and both of these tests show the same behavior:

#import <XCTest/XCTest.h>

@interface BadTests : XCTestCase

@end

@implementation BadTests

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

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

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

@end

and

#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

Reverting back to Xcode 6 with the same tests resolves the issue.

like image 695
joshbillions Avatar asked Oct 05 '15 15:10

joshbillions


1 Answers

Ended up resolving the issue by adjusting my Podfile:

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

platform :iOS, '8.1'

target 'TestApp' do
     pod 'MagicalRecord'
end

target 'TestApp' do
     pod 'OHHTTPStubs'
end

Previously my pod file just looked like this:

platform :iOS, '8.1'
pod 'MagicalRecord'
pod 'OHHTTPStubs'
like image 117
joshbillions Avatar answered Nov 15 '22 18:11

joshbillions