使用XCTest测试视图标题

 岳骏哲爱237 发布于 2023-02-11 19:20

我正在使用XCtest来测试视图的标题.试着养成先写测试的习惯.设置看起来像

- (void)setUp
{
    [super setUp];
    self.appDelegate = [[UIApplication sharedApplication] delegate];
    self.tipViewController = self.appDelegate.tipViewController;
    self.tipView = self.tipViewController.view;

    self.settingsViewController = self.appDelegate.settingsViewController;
    self.settingsView = self.settingsViewController.view;
}

问题是"settingsViewController".我有两个实际测试功能:

- (void) testTitleOfMainView{
    XCTAssertTrue([self.tipViewController.title isEqualToString:@"Tip Calculator"], @"The title should be Tip Calculator");
    //why does this not work?
    //    XCTAssertEqual(self.tipViewController.title, @"Tip Calculator", @"The title should be Tip Calculator");
}

- (void) testTitleOfSettingsView{
    //make the setttings view visible
    [self.tipViewController onSettingsButton];

    //test the title
    XCTAssertTrue([self.settingsViewController.title  isEqualToString:@"Settings"], @"The title should be Settings");
}

"testTitleOfMainView"有效.但是"testTitleOfSettingsView失败,因为self.settingsViewController是nil.我可以理解为什么.视图还没有初始化.所以我尝试将消息发送到主控制器,使settignscontroller在视图中

[self.tipViewController onSettingsButton];

settingsController仍为零.我应该使用嘲笑吗?有人建议我用另一个问题 xctest - 如何测试按钮按下时是否加载新视图

我应该将设置视图子类化并手动启动吗?谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有