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
81
votes
24 answers

Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted

I have started working with OCMock to write test cases for the existing project that I have integrated in my project workspace. After following all the steps mentioned in this link. When I first executed my test case it's giving the error above. I…
Varun Mehta
  • 1,733
  • 3
  • 18
  • 39
39
votes
5 answers

How to stub a class method in OCMock?

I often find in my iPhone Objective-C unit tests that I want stub out a class method, e.g. NSUrlConnection's +sendSynchronousRequest:returningResponse:error: method. Simplified example: - (void)testClassMock { id mock = [OCMockObject…
Jeremy
  • 2,801
  • 2
  • 30
  • 31
36
votes
6 answers

How can I use OCMock to verify that a method is never called?

At my day job I've been spoiled with Mockito's never() verification, which can confirm that a mock method is never called. Is there some way to accomplish the same thing using Objective-C and OCMock? I've been using the code below, which works but…
Justin Voss
  • 6,294
  • 6
  • 35
  • 39
33
votes
5 answers

Can OCMock run a block parameter?

Assume a method signature such as the following: - (void)theMethod:(void(^)(BOOL completed))completionBlock; I would like to mock this method signature to ensure the method is called, and just call the completion block. I see from other posts like…
Mike
  • 1,112
  • 1
  • 13
  • 20
32
votes
6 answers

Passing primitives to an OCMock's stub

I'm learning how to use OCMock to test my iPhone's project and I have this scenario: a HeightMap class with a getHeightAtX:andY: method, and a Render class using HeightMap. I'm trying to unit test Render using some HeightMap mocks. This works: id…
Eduardo Costa
  • 1,974
  • 1
  • 16
  • 22
30
votes
3 answers

Stub a Method That Returns a BOOL with OCMock

I'm using OCMock 1.70 and am having a problem mocking a simple method that returns a BOOL value. Here's my code: @interface MyClass : NSObject - (void)methodWithArg:(id)arg; - (BOOL)methodWithBOOLResult; @end @implementation MyClass -…
rentzsch
  • 3,548
  • 4
  • 27
  • 39
27
votes
4 answers

How can the return value of an OCMock stub be changed?

It seems that the first time I add andReturnValue on an OCMock stub, that return value is set in stone. For example: id physics = [OCMockObject niceMockForClass:[DynamicPhysicsComponent class] Entity *testEntity = [Entity…
Cris
  • 1,939
  • 3
  • 23
  • 37
24
votes
3 answers

How to verify number of method calls using OCMock

Is there a way to verify that a method has been called 'x' amount of times?
qnoid
  • 2,346
  • 2
  • 26
  • 45
22
votes
1 answer

Testing use of NSURLConnection with HTTP response error statuses

I'm writing an iPhone application that needs to get some data from a web server. I'm using NSURLConnection to do the HTTP request, which works well, but I'm having trouble unit testing my code in the case where the response has an HTTP error code…
Will Harris
  • 21,597
  • 12
  • 64
  • 64
19
votes
3 answers

OCMock with Core Data dynamic properties problem

I'm using OCMock to mock some Core Data objects. Previously, I had the properties implemented with Objective-C 1.0 style explicit accessors: // -- Old Core Data object header @interface MyItem : NSManagedObject {} - (NSString *) PDFName; - (void)…
amrox
  • 6,207
  • 3
  • 36
  • 57
19
votes
5 answers

How do i mock a method that accepts a handle as an argument in OCMock?

I'm trying to mock a method that has the equivalent of the following signature: - (NSDictionary *) uploadValues:(BOOL)doSomething error:(NSError **)error I want it to return a small dictionary so that my test can make sure the code uses the…
Kevlar
  • 8,804
  • 9
  • 55
  • 81
18
votes
2 answers

How do you mock out private properties with OCMock for iOS?

I have a private property that is declared in the .m file of my class to be tested, let's call it ClassUnderTest. ClassUnderTest instantiates an instance of ClassToBeMocked. How do I use OCMock to mock out an instance of the ClassToBeMocked and…
Shiun
  • 2,677
  • 1
  • 20
  • 20
15
votes
3 answers

EXC_BAD_ACCESS when accessing parameters in andDo of OCMock

I am trying to write an block of code using OCMock's stub andDo method. In this case UIImageView extension class is being tested. I want to check that the extension calls [self setImage:] with parameter that is non-nil (later other image comparison…
UrK
  • 2,191
  • 2
  • 26
  • 42
14
votes
2 answers

How to mock ** parameter in OCMock in ARC

One of the parameter of my method is **error and my project is in ARC mode. When writing stub for this method to call a mock method i set parameter to below possible values. Either it causes compile error or failing to match the argument to call the…
Saran
  • 6,274
  • 3
  • 39
  • 48
14
votes
2 answers

Returning CGRect from mocked method crashes

I was just practising OCMock, The problem I am facing here is I have one method named foo which returns CGRect, this method is called from another method callFoo. -(CGRect)foo { return CGRectMake(10, 10, 10, 10); } -(void)callFoo { CGRect…
Prasad Devadiga
  • 2,573
  • 20
  • 43
1
2 3
32 33