Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do my OCUnit tests fail with "code 138"?
    text
    copied!<p>I'm currently trying to learn objective-c using XCode 3.1. I've been working on a small program and decided to add unit testing to it. </p> <p>I followed the steps on the Apple Developer page - <a href="http://developer.apple.com/mac/articles/tools/unittestingwithxcode3.html" rel="nofollow noreferrer">Automated Unit Testing with Xcode 3 and Objective-C</a>. When I added my first test, it worked fine when the tests failed, but when I corrected the tests the build failed. Xcode reported the following error:</p> <blockquote> <p>error: Test host '/Users/joe/Desktop/OCT/build/Debug/OCT.app/Contents/MacOS/OCT' exited abnormally with code 138 (it may have crashed).</p> </blockquote> <p>Trying to isolate my error, I re-followed the steps from the Unit Test example above and the example worked. When I added a simplified version of my code and a test case, the error returned.</p> <p>Here is the code I created:</p> <p><strong>Card.h</strong></p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; #import "CardConstants.h" @interface Card : NSObject { int rank; int suit; BOOL wild ; } @property int rank; @property int suit; @property BOOL wild; - (id) initByIndex:(int) i; @end </code></pre> <p><strong>Card.m</strong></p> <pre><code>#import "Card.h" @implementation Card @synthesize rank; @synthesize suit; @synthesize wild; - (id) init { if (self = [super init]) { rank = JOKER; suit = JOKER; wild = false; } return [self autorelease]; } - (id) initByIndex:(int) i { if (self = [super init]) { if (i &gt; 51 || i &lt; 0) { rank = suit = JOKER; } else { rank = i % 13; suit = i / 13; } wild = false; } return [self autorelease]; } - (void) dealloc { NSLog(@"Deallocing card"); [super dealloc]; } @end </code></pre> <p><strong>CardTestCases.h</strong></p> <pre><code>#import &lt;SenTestingKit/SenTestingKit.h&gt; @interface CardTestCases : SenTestCase { } - (void) testInitByIndex; @end </code></pre> <p><strong>CardTestCases.m</strong></p> <pre><code>#import "CardTestCases.h" #import "Card.h" @implementation CardTestCases - (void) testInitByIndex { Card *testCard = [[Card alloc] initByIndex:13]; STAssertNotNil(testCard, @"Card not created successfully"); STAssertTrue(testCard.rank == 0, @"Expected Rank:%d Created Rank:%d", 0, testCard.rank); [testCard release]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload