gpt4 book ai didi

iphone - 单元测试核心数据 - 异常退出,代码为 134

转载 作者:行者123 更新时间:2023-12-03 19:27:59 25 4
gpt4 key购买 nike

我正在为我的核心数据应用程序设置单元测试。我在一个非常简单的测试中遇到了一个奇怪的问题。我收到的错误是:

/Developer/Tools/RunPlatformUnitTests.include:451:0 Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/Developer/usr/bin/otest' exited abnormally with code 134 (it may have crashed).

我的单元测试的标题是:

#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "Unit.h"

@interface UnitLogicTests : SenTestCase {
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSManagedObjectModel *managedObjectModel;
NSPersistentStore *persistentStore;
}
@end

实现是:

#import "UnitLogicTests.h"

@implementation UnitLogicTests

#pragma mark Setup and Teardown
- (void)setUp {
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles: nil] retain];
NSLog(@"model: %@", managedObjectModel);
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
persistentStore = [persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType
configuration:nil
URL:nil
options:nil
error:NULL];
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:persistentStoreCoordinator];
}

- (void)tearDown
{
[managedObjectContext release];
managedObjectContext = nil;
NSError *error = nil;
STAssertTrue([persistentStoreCoordinator removePersistentStore:persistentStore error:&error],
@"couldn't remove persistent store: %@", error);
persistentStore = nil;
[persistentStoreCoordinator release];
persistentStoreCoordinator = nil;
[managedObjectModel release];
managedObjectModel = nil;
}

#pragma mark -
#pragma mark Test Cases
- (void)testThatEnvironmentWorks
{
STAssertNotNil(persistentStore, @"no persistent store");
}


- (void)testNewUnitDefaults {
Unit *newUnit = [NSEntityDescription insertNewObjectForEntityForName:@"Unit"
inManagedObjectContext:managedObjectContext];
STAssertEquals(newUnit.floorNumber, 1, @"Default value for new Unit's floor number should be 1");

}

@end

如果我省略 - (void)testNewUnitDefaults 测试,则构建会毫无错误地完成,因此最后一个测试中的某些内容会使其陷入循环。我对此很陌生,因此我们将不胜感激!

谢谢。

最佳答案

我今天遇到了同样的问题,我认为 Martin Brugger 是对的,但是如果您无法获取资源,还有另一种获取 bundle 资源的方法。

您可以尝试通过以下方式获取 bundle

[NSBundle bundleForClass:[self class]]

这是我使核心数据单元测试工作的代码

NSBundle * bundle = [NSBundle bundleForClass:[self class]];
managedObjectModel_ = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]];

注意:还请确保 .xcdatamodel 包含在您的单元测试目标中

关于iphone - 单元测试核心数据 - 异常退出,代码为 134,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3241175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com