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 6951019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:09:57+00:00 2026-05-27T14:09:57+00:00

The short question is: How can I get iPhone (objective-c) file operations to work

  • 0

The short question is: How can I get iPhone (objective-c) file operations to work correctly from a command line Unit Test?

The long question, with explanation: This will eventually become a script to perform automated building/testing for my iPhone build, via a Hudson instance. Following makdad’s link on this SO question has allowed me to run Unit tests from the command line (semi) successfully.

However, one of my tests fails. The test would call a Caching Service class to save a file, then try and retrieve it. however, file I/O appears to not work when running the tests from the command line :(.

For Reference, running the Unit tests via the Xcode GUI results in no such errors.

I am using NSFileHandle method calls to get handles for writing. if they return nil, the file is created using

[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];

I thought it may have to do with the spaces in the path to the simulator’s cache directory. am I on the right track? if so, how would i rectify this?

Note also that the simulator needs to be NOT running already in order for this to work, the simulator is started programmatically and does not display a GUI. if it is running, the command line build fails.

  • 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-27T14:09:58+00:00Added an answer on May 27, 2026 at 2:09 pm

    First: ‘the simulator needs to be NOT running already in order for this to work’
    I have my tests running in the terminal and it doesn’t matter if the simulator is on.

    Maybe some build settings you have to look at are: TEST_HOST and BUNDLE_LOADER.
    I leave them empty in my xcodeproj.
    Note: I’m using Hudson as well with test reports and code coverage.

    Second:
    I have experienced failures in tests terminal and application with loading paths. This was related to the Core Data model which is loaded from a resource.
    The solution was to load the file from url instead of a path:

    [[NSBundle bundleForClass:[self class]] URLForResource:....];
    

    I cannot ensure this relates to the same problem your encountering with the NSFileManager, but i can only imagine that NSBundle makes use of the NSFileManager. (So this can be related)

    Third:
    Do not make your tests dependent on I/O.
    I find that that is not the purpose of a Unit Test. Such test may not rely on a filesystem, database, network connection, etc.

    Make an file system abstraction class that you mock while running your tests.
    This way your implementation is only at one place relying on the actual file system, which you can replace during testing.

    You only need one test to check that abstraction.

    Summary

    • The first will improve your test setup.
    • The second will hopefully solve your test problem.
    • The third will reduce the occurrence of the problem and improve your code.

    Hope this was helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short question: If I have class that impelemnts FactoryBean interface, how can I get
Long story below short question: How can I get Spring's NamedParameterJDBCTemplate join Hibernate's session?
First shot at throwing a question on these boards so hopefully I can get
A short question: I've got a TabNavigator with multiple canvas children. How can i
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
The short version of the question - why can't I do this? I'm restricted
Short question: How do I automatically detect whether a CSV file has headers in
The short question is: if I hg rollback , how does Peter get my
Short question: How can I modify individual items in a List ? (or more
Hey, sorry to bother you again, but I can't get this to work and

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.