每次测试之前,我都会尝试擦除数据并重新创建夹具。该应用程序每次点击MR_saveToPersistentStoreAndWait
时都会崩溃,但cannot find data for a temporary oid
[A MR_truncateAll];
[B MR_truncateAll];
[C MR_truncateAll];
[[FixtureLoader instance] loadDataInContext:[NSManagedObjectContext MR_defaultContext]];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
为什么会这样?
与其在测试中截断,不如使用内存存储并在每次测试后转储存储。您不会遇到崩溃,而且速度会快得多。
- (void)setUp {
[super setUp];
[MagicalRecord cleanUp];
[MagicalRecord setupCoreDataStackWithInMemoryStore];
}