I have an OCUnit Test class: PatientTestViewControllerTests. Below is the interface:
@interface PatientTestViewControllerTests : SenTestCase
@property (nonatomic, strong) PatientTestViewController *testController;
@end
and setUp:
- (void) setUp
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Testing" bundle:nil];
self.testController = [storyboard instantiateInitialViewController];
}
The 'Testing' storyboard is the only storyboard in my app, and is set as the app's main storyboard. The PatientTestViewController is set as the storyboard's only view controller.
I have one test in my test class:
- (void) testInitialTestingStoryboardViewIsPatientTest
{
STAssertTrue([self.testController isMemberOfClass:[PatientTestViewController class]], @"Instead of the %@, we have %@",[PatientTestViewController class], [self.testController class]);
}
This test fails with the following log message:
error: -[PatientTestViewControllerTests testInitialTestingStoryboardViewIsPatientTest] : "[self.testController isMemberOfClass:[PatientTestViewController class]]" should be true. Instead of the PatientTestViewController, we have PatientTestViewController
How can this be? Since
[self.testController isMemberOfClass:[PatientTestViewController class]]
is apparently false, how can the test log say that both
[self.testController class]
and [PatientTestViewController class]
look the same?
Additional Info:
- using
[self.testController isKindOfClass:[PatientTestViewController class]]
in the test also fails using
[self.testController class] == [PatientTestViewController class]
fails also.using
[self.testController isKindOfClass:[UIViewController class]]
PASSES.- using
[self.testController isMemberOfClass:[UIViewController class]]
FAILS.
NSLog(@"Expected address: %p, actual: %p",[PatientTestViewController class], [self.testController class]);
look like? – Mellifluous[UIStoryboard instantiateInitialViewController]
return something different.. and how is it different? – StormproofisMemberOfClass:
checks equality internally. I kind of suspect UIStoryboard has created a dummy stand-in class for some reason. Possibly some sort of laziness. How about this: what happens if you send a message to thetestController
, then doisMemberOfClass:
,isKindOfClass:
, and print the address? – MellifluoustestController
didn't change anything (still the same discrepancy in addresses). However, I created a new project to replicate the problem, and I can't replicate it. The only real difference between the two projects is that I was fiddling around with the Storyboards in my original. I must have done... something. – Stormproof