title: OCUnit & NSBundle
body: <p>I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test:</p>
  
  <pre><code>// myClass.h
  #import &lt;Foundation/Foundation.h&gt;
  #import &lt;UIKit/UIKit.h&gt;
  
  @interface myClass : NSObject {
      UIImage *image;
  }
  @property (readonly) UIImage *image;
  - (id)initWithIndex:(NSUInteger)aIndex;
  @end
  
  
  // myClass.m
  #import "myClass.m"
  
  @implementation myClass
  
  @synthesize image;
  
  - (id)init {
      return [self initWithIndex:0];
  }
  
  - (id)initWithIndex:(NSUInteger)aIndex {
      if ((self = [super init])) {
          NSString *name = [[NSString alloc] initWithFormat:@"image_%i", aIndex];
          NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
          image = [[UIImage alloc] initWithContentsOfFile:path];
          if (nil == image) {
              @throw [NSException exceptionWithName:@"imageNotFound"
                  reason:[NSString stringWithFormat:@"Image (%@) with path \"%@\" for current index (%i) wasn't found.",
                      [name autorelease], path, aIndex]
                  userInfo:nil];
          }
          [name release];
      }
      return self;
  }
  
  - (void)dealloc {
      [image release];
      [super dealloc];
  }
  
  @end
  </code></pre>
  
  <p>And my unit-test (LogicTests target):</p>
  
  <pre><code>// myLogic.m
  #import &lt;SenTestingKit/SenTestingKit.h&gt;
  #import &lt;UIKit/UIKit.h&gt;
  #import "myClass.h"
  
  @interface myLogic : SenTestCase {
  }
  - (void)testTemp;
  @end
  
  @implementation myLogic
  
  - (void)testTemp {
      STAssertNoThrow([[myClass alloc] initWithIndex:0], "myClass initialization error");
  }
  
  @end
  </code></pre>
  
  <p>All necessary frameworks, "myClass.m" and images added to target. But on build I have an error:</p>
  
  <p><code>[[myClass alloc] initWithIndex:0] raised Image (image_0) with path \"(null)\" for current index (0) wasn't found.. myClass initialization error</code></p>
  
  <p>This code (initialization) works fine in application itself (main target) and later displays correct image. I've also checked my project folder (<code>build/Debug-iphonesimulator/LogicTests.octest/</code>) - there are <code>LogicTests</code>, <code>Info.plist</code> and necessary image files (<code>image_0.png</code> is one of them).</p>
  
  <p>What's wrong?</p>