我正在尝试为我的核心数据代码添加一些单元测试.但我总是有这个问题,第一个测试总是正确运行,但第二个测试崩溃,因为实体名称为零.
我也得到这个错误:
Multiple NSEntityDescriptions claim the NSManagedObject subclass 'Gym.Exercise' so +entity is unable to disambiguate.
Failed to find a unique match for an NSEntityDescription to a managed object subclass
Run Code Online (Sandbox Code Playgroud)
所以我的猜测是我没有做正确的事情 tearDown().
override func setUp() {
super.setUp()
coreDataStack = CoreDataStack(storeType: .inMemory)
context = coreDataStack.context
}
override func tearDown() {
coreDataStack.reset()
context = nil
super.tearDown()
}
Run Code Online (Sandbox Code Playgroud)
这是我的CoreDataStack班级:
final class CoreDataStack {
var storeType: StoreType!
public init(storeType: StoreType) {
self.storeType = storeType
}
lazy var persistentContainer: NSPersistentContainer = {
let container …Run Code Online (Sandbox Code Playgroud)