Automated testing (unit/integration/functional testing) is a really great way to verify your app works as expected. Also, having confidence that your refactoring won’t break anything is totally cool too. I’ve been doing some tests with CoreData entities and stumbled on a weird exception when simply fetching them.
Sample code:
123456
NSFetchRequest*request=[NSFetchRequestnew];request.entity=entity;request.fetchLimit=0;NSError*error=nil;XCTAssertNotNil([mocexecuteFetchRequest:requesterror:&error],@"Failed to fetch entities: %@",error);
I couldn’t find an answer on the internets. After a while I setup a breakpoint on All Exceptions: Debug / Breakpoints / Create Exception Breakpoint. Seeing -[_NSKeyedUnarchiveFromDataTransformer transformedValue:] in the stack trace hinted me that one of the entities has a Transformable attribute with a certain class that wasn’t included in the test target. Adding it fixed the problem. Or better yet, create a mock class that simply returns the input value to minimize the application logic in the tests.