私のアプリケーションのすべてのビジネスロジックを組み込むためにフレームワークプロジェクトを作成しました。そのため、コアデータモデルもフレームワークプロジェクトに移行しました。ここでは、フレームワーク内のマネージャとモジュールクラスの単体テストを行うためのXCTestCaseクラスがいくつかあります。これらのクラスには、コアデータ操作があります。したがって、ユニットテストの間、これらのクラスはDBManagerクラスを参照します。私はこのケースでは永続的なモデルの作成で発生クラッシュしています。メインプロジェクトで同じユニットテストケースを使用したときに、すべてがうまくいきました。私が主に気付いたのは、メインプロジェクトとユニットテストケースを実行中に、永続的な作成時に作成するstoreURLが異なります。枠組み。以下は作成されたstoreURLです。 file:/// Users/Gowtham/Library/Developer/CoreSimulator/Devices/F7DB4F9B-D323-4978-A816-B5363F26BE32/data /コンテナ/データ/アプリケーション/ 92F08534-F5AD-4B4B-B1A3-D3CEF17758C0/Documents/IHA。 sqliteの[メインプロジェクト]フレームワークプロジェクトから単体テストを実行中にアプリケーションがクラッシュする
ファイル:中///Users/Gowtham/Library/Developer/CoreSimulator/Devices/F7DB4F9B-D323-4978-A816-B5363F26BE32/data/Documents/IHA.sqlite [ユニットテストケースフレームワークプロジェクト]
以下はコンソールに表示される例外です。
未解決エラーエラードメイン= YOUR_ERROR_DOMAINコード= 9999 NSUnderlyingError = 0x7be93420 {エラー ドメイン= NSCocoaErrorDomainコード、 のUserInfo = {NSLocalizedDescription =が アプリケーションの保存されたデータの初期化に失敗しました "アプリケーションの保存されたデータの初期化に失敗しました" = 134100 "(null)" UserInfo = {metadata = { NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { UserDictionaryEntry =; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers =( "" ); NSStoreType = SQLite; NSStoreUUID = "6C70A93B-39DD-4357-A0C2-0BDA5DF51E32"; "_NSAutoVacuumLevel" = 2; }、理由=ストアを開くために使用されるモデルは、ストアを作成するために使用したもの}}と互換性がない、 NSLocalizedFailureReasonは= アプリケーションの保存されたデータを作成したり、読み込みエラーが発生しました。}、{ NSLocalizedDescriptionは=「初期化に失敗しましたアプリケーションの保存されたデータ "; NSLocalizedFailureReason = "アプリケーションの保存データの作成または読み込み中にエラーが発生しました。 NSUnderlyingError = "エラードメイン= NSCocoaErrorDomainコード= 134100 \"(ヌル)\」のUserInfo = {メタデータ= {\ N NSPersistenceFrameworkVersion = 641; \ N NSStoreModelVersionHashes = {\ N
UserDictionaryEntry =; \ n}は、\ nは
"6C70A93B-39DD-4357-A0C2-0BDA5DF51E32 \" \ \ N NSStoreUUID = ; NSStoreModelVersionHashesVersion = 3; \ nは
NSStoreModelVersionIdentifiers =(\ n \ "\" \ n)が、\ nは
NSStoreType = SQLiteの\ n \ "_ NSAutoVacuumLevel \" = 2; \ n}、理由=店舗を開くために使用されたモデルが店舗の作成に使用されたモデルと互換性がありません。 }
フレームワークプロジェクトのコアデータと通信するユニットテストケースを作成する適切な方法については、誰でも私に提案していただけますか?アプリはそれがうまく働いて、DB操作のためのフレームワークプロジェクトと通信する場合
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
// Create the coordinator and store
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"IHA.sqlite"];
NSError *error = nil;
NSString *failureReason = @"There was an error creating or loading the application's saved data.";
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
:
クラッシュのDatabaseManagerクラスの次のような方法で起こっています。同時に、FrameworkプロジェクトのXCTest TargetがDB操作を呼び出すと、クラッシュが発生しています。親切に誰かに助けを求めるようにお願いします。