Tôi muốn tạo một thử nghiệm tích hợp cho thấy rằng một hành động nhất định dẫn đến hiển thị một bộ điều khiển xem phương thức. Các storyboard được thiết lập với 2 viewcontrollers, một với một lớp ViewController tùy chỉnh thứ hai với một lớp UIViewController mặc định và tiêu đề "thứ hai". Segue được thiết lập để được phương thức với định danh "modalsegue". Chạy ứng dụng trong trình mô phỏng hoạt động rực rỡ, nhưng tôi gặp rất nhiều rắc rối khi xác định một thử nghiệm chính xác.Thử nghiệm tự động các phân đoạn
ViewController.m:
@implementation ViewController
- (IBAction)handleActionByPerformingModalSegue {
[self performSegueWithIdentifier:@"modalsegue" sender:self];
}
@end
Test:
- (void)testActionCausesDisplayOfSecondViewController {
ViewController * vc =
[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:@"ViewController"];
[vc handleActionByPerformingModalSegue];
STAssertEquals(vc.presentedViewController.title, @"second",
@"Title of presented view controller should be second but is %@",
vc.presentedViewController.title, nil);
}
Chạy kết quả kiểm tra tại đầu ra sau đây:
2013-06-23 17:38:44.164 SeguesRUs[15291:c07] Warning: Attempt to present <UIViewController: 0x7561370> on <ViewController: 0x7566590> whose view is not in the window hierarchy!
SeguesRUsTests.m:33: error: -[SeguesRUsTests testActionCausesDisplayOfSecondViewController] : '<00000000>' should be equal to '<9c210d07>': Title of presented view controller should be second but is (null)
Tôi đang làm gì sai? Có cách nào dễ dàng để tránh tin nhắn đầu tiên không?
tốt, có lẽ bạn nên chuyển sang một khung trình độ cao hơn mà sẽ thực sự thử nghiệm giao diện người dùng và không một số phương pháp nội - đối với giao diện người dùng tự động hóa của thẳng thắn-dưa leo dụ của Apple. – Sulthan