iosunit-testingcore-dataxctest

XCTest with Core Data


  1. Do XCTests run in parallel (that is, are multiple tests allowed to run at the same moment?). Consider a single test file with multiple tests, and multiple test files with multiple tests each.
  2. If core data is used in some of the components being tested, and tests can run in parallel, what is the correct method of using the core data in the tests? For example, the test should start with a 'clean' data store, and then add objects as needed, then get tested based off of the contents of the store. It sounds like if they all use the same managed object context/store they'll be pointing to the same data and thus be at risk for colliding with each other.

Solution

    1. Each XCTest method is run sequentially (one at the moment)

    2. To test Core Data I often create in memory Persistance Store, here you have good snipped: code using this kind of MOC you always have clear core data state

    Please check also this Rays tutorial