When implementing TDD with Core Data and fixing issues, seemingly out of nowhere the database file can’t be accessed in the tests anymore. I get this error in the setUp method when saving the context:
Error Domain=NSCocoaErrorDomain Code=256 "The file “Model.sqlite” couldn’t be opened."
Full error:
I/O error for database at /Users/auser/Library/Developer/CoreSimulator/Devices/1ECDF95D-64CF-4B90-8B06-083BAC0CB100/data/Containers/Data/Application/001DC897-DCB4-49BA-AB67-6A1FCC4CF302/Library/Application Support/Model.sqlite. SQLite error code:1, 'near "WHERE": syntax error' with userInfo of {
NSFilePath = "/Users/auser/Library/Developer/CoreSimulator/Devices/1ECDF95D-64CF-4B90-8B06-083BAC0CB100/data/Containers/Data/Application/001DC897-DCB4-49BA-AB67-6A1FCC4CF302/Library/Application Support/Model.sqlite";
NSSQLiteErrorDomain = 1;
}
My XCTests are reading and saving the database, and so does the app.
I know the XCTests start the app in order to run tests.
Is this a threading issue? I.E. will XCTests try to access core data via a separate thread and read handle on the sqlite file?
Any ideas why would I be able to test core data for a long time and then run into this issue out of nowhere?
What I’ve done to troubleshoot:
- Google all around for this error as it pertains to Core Data and tried all of the solutions, like deleting the app from the simulator, clearing build data and cache, derived data, etc. None of these work.
Thanks for any insight or suggestions.