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

  • SEARCH
  • Home
  • 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 6923183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:30:10+00:00 2026-05-27T10:30:10+00:00

For my app i’m using a MVC-Store model. The class DataStore holds a singleton

  • 0

For my app i’m using a MVC-Store model.

The class DataStore holds a singleton object defaultstore which holds the data for the app.
Everything works out fine but i got some problems with my unit tests because i don’t want my tests mess up the data.

I would like to do the following but i don’t know how:

- (void)setUp
{
    [super setUp];

    //Backup my data
    //Clear coredata
}

- (void) testCreateSomeData
{
    //..Create some data, add it to the store, do some tests, etc..
}    

- (void)tearDown
{
    Put back my original data
    [super tearDown];
}

Oh btw, the init method of the DataStore looks like this, maybe thats of some help.

- (id) init
{
    //If we allready have a singleton object
    if(defaultStore){
        return defaultStore;
    }
    self = [super init];

    // Read in our .xcdatamodel file
    model = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];

    NSPersistentStoreCoordinator *psc =
    [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];

    NSString *path = pathInDocumentDirectory(@"store.data");
    NSURL *storeURL = [NSURL fileURLWithPath:path];
    NSError *error = nil;

    if (![psc addPersistentStoreWithType:NSSQLiteStoreType
                           configuration:nil
                                     URL:storeURL
                                 options:nil
                                   error:&error]) {
        [NSException raise:@"Open failed" format:@"Reason: %@", [error localizedDescription]];
    }

    // Create the managed object context
    context = [[NSManagedObjectContext alloc] init];
    [context setPersistentStoreCoordinator:psc];
    [context setUndoManager:nil];

    [psc release];
    return self;
}
  • 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-27T10:30:11+00:00Added an answer on May 27, 2026 at 10:30 am

    One option would be to have a designated init that takes a filename, and then have the default initializer pass in the normal file name. Then your tests could create a DataStore in a separate file, deleting it before running the tests and after, without touching your non-test data.

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

Sidebar

Related Questions

App has 4 view controllers; Menu, A, B and C, and a singleton class
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
My app has a DataGridView object and a List of type MousePos. MousePos is
My app uses the android.support.v4.view.ViewPager class. For each page in the ViewPager, I want
My app is crashing using iOS5 and iOS4.3 iPhone simulators in Xcode 4.2, the
App Engine Datastore cannot be queried for an aggregate result. Example: I have an
The app engine datastore, of course, has downtime . However, I'd like to have
App Store We have been developing an app for quite some time now for
We're building an app, our first using Rails 3, and we're having to build
My app must NOT auto -rotate at all. But it includes a screen which

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.