This is an error:
Could not cast value of type
MyApp.Member
(0x1674daf8) toMyAppTests.Member
(0x4c07248).
You can reproduce a bug in easy way:
Setup two NSManagedObject
@objc(Member)
class Member: NSManagedObject {
@NSManaged var family: Family
}
@objc(Family)
class Family: NSManagedObject {
@NSManaged var members: Set<Member>
}
Setup this also in your .xcdatamodel
:
Then in your TestFile:
func testA() {
let family = Family.MR_createEntityInContext(context)
let father = Member.MR_createEntityInContext(context)
father.family = family
let firstMember = family.members.first
XCTAssertEqual(firstMember!, father)
}
I have found a solution:
I suppose that those who has such problem, imported their files into test target this way:
Since they should do it just like this:
So, just remove the files from your test target. And then if you need your files within test target just use @testable
keyword within your every test class.
This way there is no problem with casting values between targets anymore. It worked for me:-) Enjoy:-)
Read more from Swift 2 + Xcode 7: Unit Testing Access Made Easy!!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With