ocmock

OCMock - partial mocking [UIAlertView alloc]

与世无争的帅哥 提交于 2019-12-12 13:48:29
问题 I'm having an issue with the OCMock framework for iOS. I'm essentially trying to mock UIAlertView 's initWithTitle:message:delegate ... method. The example below doesn't work in the sense that the stubbed return value isn't returned when I call the initWithTitle method. UIAlertView *emptyAlert = [UIAlertView new]; id mockAlert = [OCMockObject partialMockForObject:[UIAlertView alloc]]; [[[mockAlert stub] andReturn:emptyAlert] initWithTitle:OCMOCK_ANY message:OCMOCK_ANY delegate:nil

OCMVerify/Expect in Swift?

与世无争的帅哥 提交于 2019-12-11 13:55:21
问题 I would like to Verify that an expected method is called with the correct parameters in Swift in unit-testing. This was very easily done in Objective-C using the OCMock framework. You could do a combination of partialMocking and running OCMExpect/Verify to assert code paths with the right parameters were being called. Any idea how to do something like this in Swift? 回答1: Swift doesn't support reflection, so traditional mocking libraries aren't feasible. Instead, you need to create your own

OCMock passing any CGSize

给你一囗甜甜゛ 提交于 2019-12-11 13:15:08
问题 I'm using OCMock and I'm trying to do to something like this in one of my tests: [[mockScrollView expect] setContentSize:[OCMArg any]]; The problem is that [OCMArg any] returns an id type, and I want to use any CGSize , because I don't know it's exact value. How can I pass this argument? 回答1: With version 2.2 of OCMock you can use ignoringNonObjectArgs [[mockScrollView expect] ignoringNonObjectArgs] setContentSize:dummySize]; 回答2: AFAIK there is no way to accomplish that with OCMock. An

How can you use OCMock with NSURLConnection/delegate for a series of mock network connections?

自闭症网瘾萝莉.ら 提交于 2019-12-11 08:14:17
问题 I've implemented the code in this posting:how to unit test a NSURLConnection Delegate? and have managed to get a test case going with my code where I simulate sending a server package of data via the mock classes. This is ok to test a simple single client post / server response type situation but I want to test a conversation scenario where my code makes a post, the server sends a reply, my code makes another response, the server sends another reply etc. Has anybody done anything similar to

How to verify a partial mock has a base method invoked with args using ocmock?

只谈情不闲聊 提交于 2019-12-11 07:48:22
问题 I'm working with a very simple web service that uses a base class to reuse some commonly used functionality. The main method under test simply builds a url and then it uses a super / base method with this argument. - (void)getPlacesForLocation:(Location *)location WithKeyword:(NSString *)keyword { NSString *gps = [NSString stringWithFormat:@"?location=%@,%@", location.lat, location.lng]; NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@%@", self.baseurl, gps]]; [super

OCMock: Why do I get an unrecognized selector exception when attempting to call a UIWebView mock?

十年热恋 提交于 2019-12-11 07:32:49
问题 Edit: This was all caused by a typo in my Other Link Flags setting. See my answer below for more information. I'm attempting to mock a UIWebView so that I can verify that methods on it are called during a test of an iOS view controller. I'm using an OCMock static library built from SVN revision 70 (the most recent as of the time of this question), and Google Toolbox for Mac's (GTM) unit testing framework, revision 410 from SVN. I'm getting the following error when the view controller attempts

How to test async method in block using OCMock

人盡茶涼 提交于 2019-12-11 01:45:26
问题 I can't seem to figure out how to test this method: - (void)writer:(id)writer didFailWithError:(NSError *)error; { [self.alertView dismissWithClickedButtonIndex:0 animated:YES]; void (^alertViewBlock)(int) = ^(int buttonIndex) { if (buttonIndex == 1) { [self performSelectorOnMainThread:@selector(savePostponeReasonsAsynchronously) withObject:nil waitUntilDone:NO]; } else { NSLog(@"dismissed"); self.savePostponeReasonsQueue = nil; } }; [self showPostponeReasonFailedAlert:alertViewBlock]; }

How to mock a C-function using OCMock

冷暖自知 提交于 2019-12-11 01:24:17
问题 How do I mock a custom c-lib function using ocmock? Couldn't find anything on google, and any method stubbing functions from OCMock doesn't work 回答1: One solution could be to encapsulate that functions inside an static class and mock it. In this way you can test the functions itself and mock his usage (using the static class). 回答2: You cannot mock C functions with OCMock. You will need to use another framework. 来源: https://stackoverflow.com/questions/21685695/how-to-mock-a-c-function-using

OCMock for iPhone (iOS4, XCode 3.2.3)

£可爱£侵袭症+ 提交于 2019-12-10 19:13:58
问题 I have the last version of OCMock (1.55) and XCode 3.2.3. I have created a test bundle target in my project. What is the best way to use OCMock in my tests? When I add OCMock.framework to the test bundle, this build error appears: "_OBJC_CLASS_$_OCMockObject", referenced from: objc-class-ref-to-OCMockObject in NotificationTests.o ld: symbol(s) not found collect2: ld returned 1 exit status 回答1: I had the same problem, here is how i solved it : Delete ocmock.framework, the copy file phase, and

cannot stub class method with OCMock 2.1+ in Xcode 5.0

懵懂的女人 提交于 2019-12-10 08:11:51
问题 I know that OCMock version 2.1+ supports stubbing class methods out of the box. But for some reason it's not working with me. To make sure I isolated the problem, I simply cloned the example OCMock project (which is clearly marked as version 2.2.1) and simply added this inside testMasterViewControllerDeletesItemsFromTableView: id detailViewMock = [OCMockObject mockForClass:[DetailViewController class]]; [[[detailViewMock stub] andReturn:@"hello"] helloWorld]; in DetailViewController.h I added