Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:08:42+00:00 2026-05-15T08:08:42+00:00

I created OCUnit test in concordance with iPhone Development Guide. Here is the class

  • 0

I created OCUnit test in concordance with “iPhone Development Guide”. Here is the class I want to test:

// myClass.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@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

And my unit-test (LogicTests target):

// myLogic.m
#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import "myClass.h"

@interface myLogic : SenTestCase {
}
- (void)testTemp;
@end

@implementation myLogic

- (void)testTemp {
    STAssertNoThrow([[myClass alloc] initWithIndex:0], "myClass initialization error");
}

@end

All necessary frameworks, “myClass.m” and images added to target. But on build I have an error:

[[myClass alloc] initWithIndex:0] raised Image (image_0) with path \"(null)\" for current index (0) wasn't found.. myClass initialization error

This code (initialization) works fine in application itself (main target) and later displays correct image. I’ve also checked my project folder (build/Debug-iphonesimulator/LogicTests.octest/) – there are LogicTests, Info.plist and necessary image files (image_0.png is one of them).

What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:08:42+00:00Added an answer on May 15, 2026 at 8:08 am

    Found only one solution for this problem.

    When I build my unit-tests, the main bundle’s path is not equal to my project’s bundle (created .app file). Moreover, it’s not equal to LogicTests bundle (created LogicTests.octest file).

    Main bundle for unit-tests is something like /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/Developer/usr/bin. And that’s why program can’t find necessary resources.

    And the final solution is to get direct bundles:

    NSString *path = [[NSBundle bundleForClass:[myClass class]] pathForResource:name ofType:@"png"];
    

    instead of

    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have multiple options. For each option you should probably… May 16, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer What you are searching for is CREATE TABLE IF NOT… May 16, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer There is VBAUnit for free on SourceForge. Also, the commercial… May 16, 2026 at 6:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've been developing a Mac OS X framework and I want to use OCUnit
Created by Microsoft as the foundation of its .NET technology, the Common Language Infrastructure
I created a repository in my local machine: svnadmin create /home/me/Desktop/svn_test/trunk Then import myDir
I created a simple .so library containing definition of a C++ class which should
I created a calculator class that does basic +,-, %, * and sin, cos,
I created an h1 element that gets a class added to it and removed
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created a stored procedure in SQL 9 (2005) and have since upgraded to SQL
Created a Java application to upload documents via CIS (Content Integration Suite) to a
Created a UITextField for Postal Code/ZIP field with a keyboardType of UIKeyboardTypeDefault. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.