isMemberOfClass returns no when ViewController is instantiated from UIStoryboard

后端 未结 2 2033
长情又很酷
长情又很酷 2020-12-01 20:35

I have an OCUnit Test class: PatientTestViewControllerTests. Below is the interface:

@interface PatientTestViewControllerTests : SenTestCase

@property (nona         


        
相关标签:
2条回答
  • 2020-12-01 20:46

    The problem is likely that your view controller's .m file is included in both targets, the app and the test bundle. ocunit (and derivatives like Kiwi) uses 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 two copies of the same class, which is why they have the same description but different memory addresses.

    0 讨论(0)
  • 2020-12-01 20:48

    You generally want isKindOfClass: and not isMemberOfClass:. The difference is that isKindOfClass: will return YES if the receiver is a member of a subclass of the class in question, whereas isMemberOfClass: will return NO in the same case.

    You could also directly compare the classes using [self.testController class] == [PatientTestViewController class].

    0 讨论(0)
提交回复
热议问题