gpt4 book ai didi

ios - OCMock 部分模拟给出意外调用

转载 作者:行者123 更新时间:2023-11-29 13:12:22 27 4
gpt4 key购买 nike

我有一个测试(使用 OCMock)验证在发送特定通知时调用了一个方法:

- (void)testThatVCRegistersToLocationUpdateNotification {
IssueDetailsViewController* vc = [[IssueDetailsViewController alloc] init];
id mockVC = [OCMockObject partialMockForObject:vc];
[[mockVC expect] locationDidUpdate:[OCMArg any]];
[vc viewDidLoad];

[[NSNotificationCenter defaultCenter] postNotificationName:LOCATION_DID_UPDATE object:nil];

[mockVC verify];
}

这是错误:

error: testThatVCRegistersToLocationUpdateNotification (IssueDetailsViewControllerTests) failed: -[UIView setContentSize:]: unrecognized selector sent to instance 0x82cfb30

这是 viewDidLoad 方法(有点困惑):

- (void)viewDidLoad
{
[super viewDidLoad];

//[self.contentView setBackgroundColor:[UIColor redColor]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(locationDidUpdate:) name:LOCATION_DID_UPDATE object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidSelectCategories:) name:USER_DID_SELECT_CATEGORIES object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];

UIView* keyboardAccessoryView = [STUtils getKeyboardAccessoryView];
[self.titleTextField setInputAccessoryView:keyboardAccessoryView];
[self.descriptionTextView setInputAccessoryView:keyboardAccessoryView];
[self.addressTextField setInputAccessoryView:keyboardAccessoryView];

[self.view addSubview:self.contentView];
((UIScrollView *)self.view).contentSize = self.contentView.frame.size;
[((UIScrollView*)self.view) setShowsVerticalScrollIndicator:NO];

[self.descriptionTextView.layer setBorderColor:[UIColor blackColor].CGColor];
[self.descriptionTextView.layer setBorderWidth:1.0f];

//[self.categoriesTextField setUserInteractionEnabled:YES];


UIBarButtonItem* reportButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(reportButtonClicked:)];

self.navigationItem.rightBarButtonItem = reportButton;

if (ISSUE_CREATION_MODE == self.viewControllerMode) {
[[STLocationManager sharedInstance] startLocating];
}

if (ISSUE_EDITING_MODE == self.viewControllerMode) {

self.titleTextField.text = self.parameters[@"title"];
self.longitudeLabel.text = [NSString stringWithFormat:@"%@", self.parameters[@"lon"]];
self.latitudeLabel.text = [NSString stringWithFormat:@"%@", self.parameters[@"lat"]];

if (self.parameters[@"description"]) {
self.descriptionTextView.text = self.parameters[@"description"];
}

if (self.parameters[@"categories"]) {
self.categories = self.parameters[@"categories"];
self.categoriesTextField.text = [self.categories componentsJoinedByString:@", "];
}

if (self.parameters[@"address"]) {
self.addressTextField.text = self.parameters[@"address"];
}

for (int imageIndex=0;imageIndex<self.images.count;imageIndex++) {

UIImageView *imageView = [[UIImageView alloc] init];
[imageView setTag:PHOTO_TYPE_EXISTING];
[imageView setImageWithURL:[NSURL URLWithString:[WebserviceAPI urlByAppendingString:self.images[imageIndex]]]];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[self addImageViewToCarousel:imageView];
}
}
}

最佳答案

我的猜测是,无论您在哪里声明 vc.view 是 ScrollView ,都不会被执行。如果您对 [IssueDetailsViewController view] 进行 stub 以返回类型为 UIScrollView 的 Mock 对象会怎样?

关于ios - OCMock 部分模拟给出意外调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16898715/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com