Reputation: 1881
I'd like to create a clone of my CoreData structure (not the data) in memory. This would allow me to write my unit tests with a fresh CoreData stack, and not have to deal with data currently stored in the actual SQLite database.
As a side note I'm using MagicalRecord, which may or not help.
What I have in mind for my unit tests would be something as follow:
- (void)setUp
open the app CoreData store (SQLite)Any idea? Or better solution?
Thanks
Upvotes: 1
Views: 258
Reputation: 33421
MagicalRecord contains a function called [MagicalRecord setupCoreDataStackWithInMemoryStore]
. This will create an in-memory store based on your data model. There is no need for copying or any of the stuff you mentioned because this type of store is not persistent (you said you will just delete it all anyway before you actually use it). So don't worry about cloning the SQL version, just set up a memory version and use it.
Upvotes: 0
Reputation: 69687
I suggest following this guide I wrote: http://www.cimgf.com/2012/05/15/unit-testing-with-core-data/
It goes over the way to set up a stack with an in memory store for use with unit tests.
Upvotes: 0