Reputation: 8584
This would be common problem in CoreData unit testing using swift. EXC_BREAKPOINT exception happens due to swift's namespace differences between normal module and test module. I'm still struggling against this issue even though some solutions are introduced.
What I did and my problem is here.
func testExample() { let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate }
lazy var managedObjectModel: NSManagedObjectModel = { // The managed object model for the application. This property is not optional... let modelURL = NSBundle.mainBundle().URLForResource("CoreDataSample", withExtension: "momd")! let managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL)! // Check if we are running as test or not let environment = NSProcessInfo.processInfo().environment as [String : AnyObject] let isTest = (environment["XCInjectBundle"] as? String)?.pathExtension == "xctest" // Create the module name let moduleName = (isTest) ? "CoreDataSampleTests" : "CoreDataSample" // Create a new managed object model with updated entity class names var newEntities = [] as [NSEntityDescription] for (_, entity) in enumerate(managedObjectModel.entities) { let newEntity = entity.copy() as NSEntityDescription newEntity.managedObjectClassName = "\(moduleName).\(entity.name)" newEntities.append(newEntity) } let newManagedObjectModel = NSManagedObjectModel() newManagedObjectModel.entities = newEntities return newManagedObjectModel }()
What I want to know are two things.
How to avoid EXC_BREAKPOINT exception. Test methods seem to work normally but EXC_BREAKPOINT exception temporary stop the process at every test methods. I have to resume it every time. It very hard to run the test methods.
If I cannot avoid EXC_BREAKPOINT, I want to ignore the EXC_BREAKPOINT exception when executing unit tests.
Any help or suggestion would be helpful for me.
Thanks,
FYI:
Swift cannot test core data in Xcode tests?.
Edit:
XCode Version is 6.2
Upvotes: 1
Views: 1504
Reputation: 4526
As Wolfgang said I think the Jesse Squires solution works (it does for me) but there are several steps:
(This is not necessary but will help keep things tidy as the following steps involve making a lot of things public and that will spread through your whole project if you do not separate it out.)
You should end up with entities that look like this:
import Foundation
import CoreData
@objc(ClassName)
public class ClassName: NSManagedObject {
@NSManaged public var property: Type
}
There is an alternative approach in the SO answer here that also works.
Edit 1: Added note about alternative.
Edit 2: Passed on tip to move Core Data into a separate module.
Upvotes: 3