Questions tagged [ocmock]

OCMock is an Objective-C implementation of mock objects.

The OCMock framework provides the ability of using mock objects in Objective-C applications. Some of the functionality in the framework is:

  • Create fail-fast and nice mocks.
  • Ability to stub and return predetermined values.
  • Mock instance and class methods.
  • Mock protocols and notification observers.
  • Partial mocks to stand in for a real object.
  • Forward messages to other objects.

Relevant links

Web site

Source

484 questions
0
votes
2 answers

How can I setup a mock object to fall through to the actual implementation defined in categories?

I have an objective-c class X with method turtle that I would like to mock with OCMock to unit test a class T. //X.h @interface X -(void) turtle; @end Class T includes a category and uses that to communicate with X. The category method calls…
JE42
  • 4,881
  • 6
  • 41
  • 51
0
votes
1 answer

OCMock test fails to build: Foundation/Foundation.h : No such file or directory

I am a Xcode beginner, and am facing some problems in compiling an OCMock test. I have added the OCMock.framework in "Groups & Files", and then added a very basic OCMock test from the Unit testing target, basically for Canary testing. When I…
0
votes
1 answer

OCMock fails when expecting and calling isEqual on Custom isEqual implementation

Consider the following code OCMockObject *mock = [OCMockObject mockForClass:[NSObject class]]; [[[mock expect] andReturnValue:OCMOCK_VALUE((BOOL){YES})] isEqual:[OCMArg any]]; [mock isEqual:[NSObject new]]; [mock verify]; Can someone, please, tell…
L_Sonic
  • 594
  • 6
  • 22
0
votes
2 answers

How to stub a call to a method with a reference argument?

Consider this: +(NSDictionary *)getDictionaryFromData:(id)data { @synchronized(self) { NSError *error = nil; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; …
Spencer Müller Diniz
  • 1,318
  • 2
  • 14
  • 19
0
votes
2 answers

OCMock: mocked protocol isn't stopped correctly

I have a test case using OCMock which does the following: CAAOAuth2AuthenticationManager *oAuth2AuthManager = [[CAAOAuth2AuthenticationManager alloc] init]; id authDelegate = [OCMockObject mockForProtocol:@protocol(CAAAuthenticationDelegate)]; id…
Denis Loh
  • 2,194
  • 2
  • 24
  • 38
0
votes
1 answer

Mocking NSNotificationCenter with OCMock sometimes fails unless a delay is added

Mocking NSNotificationCenter sometimes may fail if a delay is not introduced apparently. I created a simple test project where I added a single test to test notifications id mock = [OCMockObject observerMock]; [[NSNotificationCenter defaultCenter]…
Colin Wheeler
  • 3,343
  • 2
  • 21
  • 23
0
votes
1 answer

Automatic C/C++ mock generation for XCTest - CMock/OCMock?

I want to develop using C & C++ using XCode 5. I particularly like the integration of XCTest and Xcode and the CI capability that you get by using OSX Server. I want to have a mocking framework, and ideally one where the mocks are automatically…
John
  • 10,837
  • 17
  • 78
  • 141
0
votes
2 answers

Why does my test fail with "expected method was not invoked" when using a real parameter but pass when using `[OCArg isNotNil]`?

I'm testing a method using OCMock. The method is as follows: - (NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(NSDictionary *)parameters block:(void (^)(id responseObject, NSError…
Paul Young
  • 1,489
  • 1
  • 15
  • 34
0
votes
2 answers

How should I test if block has been evoked in this class?

I've got UITableView which has delegate and separated datasource. DataSource is subclass of NSObject - ArrayDataSource class. #import typedef void (^ConfigureCellBlock)(id cell, id object); @interface ArrayDataSource :…
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
0
votes
2 answers

OCMock Unrecognized Selector for mocked object

I have an error that seems to be related to OCMockObject PartialMock. When mocking an object and stubbing a method I get this unrecognized selector error which I'm pretty sure is an order or casting issue. Here's my test STV_StreamServer *server =…
Alex Reynolds
  • 6,264
  • 4
  • 26
  • 42
0
votes
1 answer

Unit Test CLLocationManager implementation

I have a class named "GeolocationManager" that handles a CLLocationManager object and delegate responses. - (void)getGeolocationForClient:(id)client { _delegate = client; _locationManager = [self…
ennzhed
  • 186
  • 2
  • 13
0
votes
1 answer

mocking a class - iOS

Im new to unit testing and OCMock so this might be an obvious answer, just didn't find answer on google. I am trying to test a model object's method. the method has the following code: //takes a filepath and a pk, sets the filepath to…
Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43
0
votes
3 answers

Not feasible to call NSInvocation from a SenTestCase derived class?

Is NSInvocation class not meant to be called via unit tests (for iPhone)? My intent is to call a class's method generically and since the method has more than 2 parameters, I can't use [myTestClass performSelector:withObject:withObject] Instead, I'm…
Alexi Groove
  • 6,646
  • 12
  • 47
  • 54
0
votes
1 answer

method pointer argument sets local ivar

Here's the method I want to test: -(bool) myMethod:(NSArray*) argArray { self.mArray = argArray; if (self.mArray == nil) { NSLog(@"Error - array is nil"); return NO; } return YES; } I am not quite sure how to setup a…
GW.Rodriguez
  • 1,181
  • 8
  • 18
0
votes
1 answer

OCMock: niceMockForClass expect zero call to method

In a test with OCMock, I must assert that no call is made to the setState: selector. However, I can make no assumption about the other calls that are made to the object. Because any other call can be made, I have to (or do I?) use a…
aspyct
  • 3,625
  • 7
  • 36
  • 61