小编chu*_*owa的帖子

当从UIStoryboard实例化ViewController时,isMemberOfClass返回no

我有一个OCUnit Test类:PatientTestViewControllerTests.以下是界面:

@interface PatientTestViewControllerTests : SenTestCase

@property (nonatomic, strong) PatientTestViewController *testController;

@end
Run Code Online (Sandbox Code Playgroud)

和setUp:

- (void) setUp
{    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Testing" bundle:nil];
    self.testController = [storyboard instantiateInitialViewController];
}
Run Code Online (Sandbox Code Playgroud)

"测试"故事板是我应用程序中唯一的故事板,并被设置为应用程序的主要故事板.PatientTestViewController被设置为故事板的唯一视图控制器.

我的测试课中有一个测试:

- (void) testInitialTestingStoryboardViewIsPatientTest
{
    STAssertTrue([self.testController isMemberOfClass:[PatientTestViewController class]], @"Instead of the %@, we have %@",[PatientTestViewController class], [self.testController class]);
}
Run Code Online (Sandbox Code Playgroud)

此测试失败,并显示以下日志消息:

错误: - [PatientTestViewControllerTests testInitialTestingStoryboardViewIsPatientTest]:"[self.testController isMemberOfClass:[PatientTestViewController class]]"应为true.取而代之的是的PatientTestViewController,我们有PatientTestViewController

怎么会这样?以来

[self.testController isMemberOfClass:[PatientTestViewController class]]

显然是错误的,测试日志怎么能说两者都有

[self.testController class][PatientTestViewController class]

看起来一样?

附加信息:

  • 使用[self.testController isKindOfClass:[PatientTestViewController class]]测试也失败
  • 使用[self.testController class] == [PatientTestViewController …

unit-testing objective-c ocunit ios

4
推荐指数
1
解决办法
1518
查看次数

标签 统计

ios ×1

objective-c ×1

ocunit ×1

unit-testing ×1