'Unit test: Xcode CoreData: error: Failed to load model named xxx

I'm using CoreData runs smoothly on my project target.

When I run it on my unit test target then it works too.

But when I set the unit test Host Application like below:

enter image description here

And fixed the linked errors by clicking the files name and add Target Membership to the unit test target.

Then I come across this error:

CoreData: error:  Failed to load model named 

I checked the coredata file name is abc.xcdatamodeld and the code is

let persistentContainer = NSPersistentContainer(name: "abc")

Also the abc.xcdatamodeId under tests target too.

Why this happen? Any ideas? thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source