Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've encountered this numerous times myself, and it's always annoying. Basically, it usually means that your unit tests <em>did</em> crash, but doesn't help isolate the error. If the unit tests produced output before crashing (open Build > Build Results) you can usually at least get an idea of what test was running when the problem occurred, but this alone usually isn't too helpful.</p> <p>The best general suggestion for tracking down the cause is to <strong>debug your unit tests</strong>. When using OCUnit, this is unfortunately more complex than selecting Run > Debug. However, the same tutorial you're using has a section near the bottom titled "<strong>Using the Debugger with OCUnit</strong>" which explains how to create a custom executable in Xcode to execute your unit tests in a way that the debugger can attach to. When you do, the debugger will stop where the error occurred, instead of getting the mysterious "code 138" when everything goes down in flames.</p> <p>Although I may not be able to guess exactly what's causing the error, I do have a few suggestions...</p> <ul> <li><strong>NEVER, EVER autorelease <code>self</code> in an init method — it violates retain-release memory rules.</strong> That alone will lead to crashes if the object is released unexpectedly. For example, in your <code>testInitByIndex</code> method, <code>testCard</code> comes back autoreleased — therefore, <code>[testCard release]</code> on the last line == guaranteed crash.</li> <li>I'd suggest renaming your <code>initByIndex:</code> method to <code>initWithIndex:</code>, or even switching to <code>initWithSuit:(int)suit rank:(int)rank</code> so you can pass both values, instead of a single <code>int</code> (or an <code>NSUInteger</code>, which would eliminate testing for &lt; 0) that you have to handle.</li> <li>If you <em>really</em> want a method that returns an autoreleased object, you can also create a convenience method like <code>+(Card*)cardWithSuit:(int)suit rank:(int)rank</code> instead. This method would just return the result of a one-line alloc/init/autorelease combination.</li> <li>(Minor) Once you're done debugging, get rid of the <code>dealloc</code> that just calls to super. If you're trying to find memory that's never deallocated, it's much easier to find using Instruments anyway.</li> <li>(Niggle) For your test method, consider using <code>STAssetEquals(testCard.rank, 0, ...)</code> instead. It tests the same thing, but any resulting error is a bit easier to understand.</li> <li>(Trivial) You don't have to declare unit test methods in the <code>@interface</code>. OCUnit dynamically runs any method of the format <code>-(void)test...</code> for you. It doesn't hurt to declare them, but you'll save yourself some typing if you just omit them. On a related note, I usually have only a .m file for unit tests, and put the @interface section at the top of that file. This works great since nobody else needs to include my unit test interface.</li> <li>(Simplicity) Unless you subclass <code>CardTestCases</code>, it is simpler to just eliminate the .h file and put the @interface at the top of the .m file instead. Header files are necessary when multiple files need to include the declarations, but this is usually not the case with unit tests.</li> </ul> <p>Here is what the test file might look like with these suggestions:</p> <p><strong>CardTest.m</strong></p> <pre><code>#import &lt;SenTestingKit/SenTestingKit.h&gt; #import "Card.h" @interface CardTest : SenTestCase @end @implementation CardTest - (void) testInitWithIndex { Card *testCard = [[Card alloc] initWithIndex:13]; STAssertNotNil(testCard, @"Card not created successfully"); STAssertEquals(testCard.rank, 0, @"Unexpected card rank"); [testCard release]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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