当您创建XCode 4项目时,它会询问您是否要包含单元测试.但是,如何将它添加到没有它们的项目中呢?
我开始了一个单元测试的项目,试图找出它,看起来它和我现有的项目之间的唯一区别是新项目中的Test.h和Test.m文件.
但是,当我将它们移动到我的旧项目并尝试构建时,它说没有这样的文件或目录:SenTestingKit/SenTestingKit.h.这对我来说看起来像一个框架,但是如果我去构建阶段并尝试添加框架,那么没有一个可用的SenTestingKit :(而新项目只链接常见的嫌疑人:UIKit,CoreGraphics和Foundation,但是没有SenTestingKit.
我有一个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 …