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
2
votes
0 answers

OCMock observer mock pattern for NotificationCenter vs partial mock

OCMock has a special way to mock/spy NSNotificationCenter. You can use it to see if a given notification was posted like this: id observerMock = OCMObserverMock(); [NSNotificationCenter.defaultCenter addMockObserver:observerMock…
stonedauwg
  • 1,328
  • 1
  • 14
  • 35
2
votes
1 answer

How does OCMock works?

We've been using OCMock for unittesting and it works very nicely. We're just not sure how does it work. Monkey patching? Code-generation on preprocess? I've tried Googling it without success. Anyone knows how does OCMock do it magic?
Michael
  • 3,206
  • 5
  • 26
  • 44
2
votes
0 answers

OCMock not found when imported outside test target

I'm trying to use OCMock to mock a network connection in order to stub my network requests for testing purposes using XCode UI Tests. As XCode UI Tests are run on a different instance than the app, I can't access my project's code from the tests,…
ecatalano
  • 687
  • 1
  • 4
  • 17
2
votes
1 answer

OCMock: OCMPartialMock object calls the actual method rather than the stub

I have 2 methods in a class where one of them simply calls the other one with specific parameters. The methods are as below: -(void)loadAllFollowersForUser:(NSUInteger)userID withResponseHandler:(_Nullable CompletionHandler)handler { [self…
Numan Tariq
  • 1,296
  • 1
  • 9
  • 18
2
votes
1 answer

Can't Stub [CLLocationManager AuthorizationStatus] with OCMock

I tried stubbing AuthorizationStatus, but it alway returns kCLAuthorizationStatusResticted no matter what I do. OCMStub([CLLocationManager authorizationStatus]).andReturn(kCLAuthorizationStatusAuthorizedAlways); What did I do wrong?
iamarnold
  • 705
  • 1
  • 8
  • 22
2
votes
1 answer

Verify a method was called from another object OCMock

I have two classes. Object 1: - (void) methodA { ObjectB objectB = [[ObjectB alloc] init]; [objectB methodB]; } And Object 2: - (void) methodB { // Does something } Using OCMock, how do I verify that methodA calls methodB? I'm setting…
nland
  • 669
  • 1
  • 7
  • 21
2
votes
1 answer

How to stub method with response block using OCMock

I have a method that calls a request with a response block inside. I want to stub my response and return fake data. How can this be done? -(void)method:(NSString*)arg1{ NSURLRequest *myRequest = ........... [self request:myRequest…
iamarnold
  • 705
  • 1
  • 8
  • 22
2
votes
1 answer

Verify a method is called twice with two different parameters

I would like to test that a method is called twice, the first time passing YES for a parameter, the second time NO. What complicates things is that the method I would like to test is a class method, I'm not sure whether this has anything to do with…
Joachim Kurz
  • 2,875
  • 6
  • 23
  • 43
2
votes
1 answer

Is it possible to stub NSProcessInfo with OCMock?

I want to stub [[NSProcessInfo processInfo] operatingSystemVersion] to take any OS version. id processInfoMock = OCMClassMock([NSProcessInfo class]); [OCMStub([processInfoMock operatingSystemVersion]) andReturnValue:NULL]; NSOperatingSystemVersion…
Keita
  • 1,478
  • 2
  • 14
  • 18
2
votes
1 answer

OCMArg checkWithBlock is crashing with EXC_BAD_ACCESS

This is how my test looks like: // In setUp: self.APIClientMock = OCMClassMock([APIClient class]); OCMStub([self.APIClientMock sharedClient]).andReturn(self.APIClientMock); // In test method: OCMVerify([self.APIClientMock POST:@"invitations"…
iosdude
  • 1,131
  • 10
  • 27
2
votes
0 answers

Mocking a model class inherit from SDK Object

I am getting start with writing unit test for all my models classes in my project. There is a class method in QUUserModel I would like to test in this case: + (BOOL)isRegistedPhoneNumber:(NSString *) phoneNumber{ AVQuery *query = [AVUser…
Zigii Wong
  • 7,766
  • 8
  • 51
  • 79
2
votes
0 answers

Xcode debugger steps over methods that execute via forwardInvocation

I noticed the following behavior when using OCMock, and after poking around I discovered it is an issue with how the Xcode debugger handles methods that are not implemented. Here's an example: @implementation ForwardingClass - (id)init { self…
David
  • 2,429
  • 24
  • 15
2
votes
0 answers

How to use XCTest&OCMock to test method which return block?

here is my RegisterService.h import "UserObject.h" @interface RegisterService : NSObject - (void)sharedInstance; - (void)registerWithPhoneNum:(NSString *)phoneNum password:(NSString *)password result:(void (^)(UserObject *userObject))successBlock…
user4728148
2
votes
0 answers

Running unit test to see if UIButton is connected to IBAction via Storyboard

I am trying to create some tests in Xcode for my view controllers, including tests to check IBOutlets and IBActions. These work fine if I am using a basic view controller + xib file, but if I use a Storyboard file then the actions don't appear to be…
jowie
  • 8,028
  • 8
  • 55
  • 94
2
votes
1 answer

Mock internal calls of a another class methods

I am trying to learn unit testing with ocmock. I am finding it difficult to mock calls of another class from a class which i am unit testing. Can some one suggest how to make mock call to KeyChainUtils class and HttpRequest class: Code to unit test…
Rajeev
  • 4,762
  • 8
  • 41
  • 63