Swift cannot test core data in Xcode tests?

前端 未结 5 624
失恋的感觉
失恋的感觉 2021-02-02 12:42

I am working on a iOS project that uses core data. I am using swift. The Core Data stack is setup right and all seems to be fine. I have created a class for an entity (NSManage

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 13:34

    With Xcode 7, and @testable, you should no longer need to update the managedObjectClassName or use other hacks. Here's what I did to get it working in Xcode 7.2.

    1. Set your test target Host Application and check "Allow testing Host Applications APIs".

    1. Make sure none of your regular classes have a Target Membership pointing to the Test target. Only classes with unit test code should be set to the Test target.

    1. Add the @testable line to the top of all of your test classes:
    import XCTest
    @testable import MyApp
    
    class MyAppTests: XCTestCase {
    }
    

    If you're still having issues you may want to try these additional tips: https://forums.developer.apple.com/message/28773#28949

    I fought with this one for a while so I hope it helps someone else out.

提交回复
热议问题