1

appDelegate 实例显示 nil 值,测试用例“testAppDelegate”失败。苹果开发者网站提供的示例代码也是如此,但正在使用 SenTestCase,请帮帮我,即使目标是根据 WWDC 2013 视频“Testing in Xcode 5 session 409”设置的

@interface Tests : XCTestCase
{
    AppDelegate *appDelegate;
    AppViewController *appVC;
    UIView *appView;
}
@end

@implementation Tests

- (void)setUp
{
    [super setUp];
    appDelegate = [[UIApplication sharedApplication] delegate];
    appVC = appDelegate.appViewController;
    appView = appVC.view;

 }

 - (void)tearDown
 {
     [super tearDown];
 }

 - (void)testAppDelegate
{
    XCTAssert(appDelegate, @"Cannot find the application delegate");
}

- (void)testCheckForViewInitializatio
{
    XCTAssert(appVC, @"AppViewController initialized");
}
4

2 回答 2

0

尝试这个:

  • 转到项目设置
  • 选择你的测试目标
  • 常规选项卡中将目标部分切换到您的主要目标

再次运行

于 2014-02-04T14:16:16.250 回答
0

安东给出了正确的建议。但如果它不起作用(如我的情况),请尝试:

  1. 删除现有的测试目标

  2. +创建新的测试目标(左窗格中的第 5 个选项卡 ->在左下角单击-> 新测试目标)和

  3. 在出现的窗口中不要忘记选择您的应用程序作为测试目标的目标。

  4. 将所有 TestCases 文件添加到新目标。

我不知道原因,但是在此操作之后,当我使用新目标运行测试时,它开始正常工作。

于 2014-07-11T06:14:40.160 回答