Xcode 7 Magical Record Unit Tests Fail
Asked Answered
R

2

13

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.

Ribeiro answered 5/10, 2015 at 15:17 Comment(6)
I have the same issue, with the same code. Have you found a solution ?Icefall
Which version of MR are you using? I've encountered the same issue with 2.2 but haven't yet tested with 2.3Dyl
I'm using 2.3.0 installed via CocoaPods. Could this be caused by not linking the tests against something that MR is looking for?Ribeiro
What's the rest of the call stack?Acetum
still no solution to this? I'm facing the same :(Rayfordrayle
any resolution to this ?Sorghum
R
1

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'
Ribeiro answered 28/1, 2016 at 19:20 Comment(0)
C
0

This situation can stem from the presence of old runtime environment as mentioned in the release notes:

Xcode processes may quit unexpectedly if older iOS Simulator runtimes (Xcode 6.x) are present on disk

To check whether this is the cause, you can delete all old runtime libraries from /Library/Developer/CoreSimulator/Profiles/Runtimes

Cafard answered 6/11, 2015 at 16:40 Comment(1)
No Xcode processes are unexpectedly quitting from what I can tell. The issue seems to be with Magical Record. I removed all of the old runtime libraries from that directory and got the same results.Ribeiro

© 2022 - 2024 — McMap. All rights reserved.