Reputation: 10129
I have three classes: ClassA, ClassB and ClassC.
ClassC inherits from ClassB which inherits from ClassA.
I'm trying to write a unit test to verify that ClassC inherits from ClassB:
XCTAssertTrue([ClassC isSubclassOfClass:[ClassB class]]);
this returns false.
XCTAssertTrue([ClassC isSubclassOfClass:[ClassA class]]);
returns true.
[ClassC class] superclass]
returns ClassB.
Note as well when I test [ClassC isSubclassOfClass:[ClassB class]]
in the console it returns true, even when I test this immediately before the code in my unit test returns false for the same test!
Can anyone explain how this could happen?
I tried Bryan's suggestion from the comments. Logging from my unit test I get:
0x102a8c4e0 0x110d21820
Logging from the console I get:
0x102a8c4e0 0x102a8c4e0
Upvotes: 0
Views: 243
Reputation: 3940
It's likely you have some of the classes added to both your app target and your unit test target.
Your class should only ever be added to the app target.
From your edit, it looks like it's ClassB
that's at fault - but it's worth checking all three of them.
SenTest/XCTest use a test harness that makes the classes included in the app available to tests without having to explicitly include their implementation.
Including both has given you duplicates of the classes, which is why they have different memory addresses.
Upvotes: 2