Unit Testing in XCode: Test rig '[...]/usr/bin/otest' exited abnormally with code 134
I have got a problem when unit testing a class. When running my test, it compiles without any errors but then it crashes (it does NOT fail in the sense of an assertion not being met), displaying the following error message:
/Developer/Tools/RunPlatformUnitTests.include:451:0 Test rig '/Developer/Platforms
/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/Developer/usr/bin/otest'
exited abnormally with code 134 (it may have crashed).
Here's my code:
The class' interface:
@interface AbstractActionModel : NSObject
{
NSString* mName;
ActionType mType; // enum
float mDuration;
float mRepeatCount;
float mDelay;
NSArray* mTriggerAreas;
}
The implementation:
- (void) dealloc
{
[mTriggerAreas release];
[super dealloc];
}
- (id) initWithConfigData: (NSDictionary*) theConfigData
{
NSAssert(nil != theConfigData, @"theConfigData cannot be nil");
self = [super init];
if (self)
{
self.name = [theConfigData objectForKey:ACTION_NAME];
self.type = [[theConfigData objectForKey:ACTION_TYPE] intValue];
self.duration = [[theConfigData objectForKey:ACTION_DURATION] floatValue];
self.delay = [[theConfigData objectForKey:ACTION_DELAY] floatValue];
self.repeatCount = [[theConfigData objectForKey:ACTION_REPEAT_COUNT] floatValue];
self.triggerAreas = [theConfigData objectForKey:ACTION_TRIGGER_AREAS];
}
return self;
}
Here's the test code:
- (void) testCreateAction
{
SoundActionModel* testSoundAction = (SoundActionModel*)[SoundActionModelFactory createActionModel:self.actionConfig];
STAssertNotNil(testSoundAction, @"returned object must not be nil");
}
The Factory's createActionModel:
method:
+ (AbstractActionModel*) createActionModel:(NSDictionary *)config
{
NSAssert(config != nil, @"config must not be nil");
SoundActionModel* retVal = [[[SoundActionModel alloc] initWithConfigData:config] autorelease];
return retVal;
}
As previously mentioned: The code compile开发者_如何转开发s, and it runs when testCreateAction
is commented out. The problem does not seem to be the test itself (i.e. its assertion).
Telling from these postings (similar problem 1, similar problem 2) it seems to be a bug in XCode, but these links point to problems which arise when using Core Data (which I don't) or OCMock (which I don't, either - at least not knowingly).
Can someone tell me how to solve this kind of problem? If it turns out to be a bug, a workaround would be very much appreciated.
I also had this problem when starting out with OCUnit. This is caused by attempting to execute as test that is setup in Logic test mode, rather than application test mode. If the code under test has some dependency on Cocoa or Cocoa Touch, this code must be run with a target set up for application test.
The fact that the test runner itself crashes looks like an xcode bug to me as AppCode will continue passed this point.
A good source for setting up these tests is here
精彩评论