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

Using OCMock to expect category methods yields "[NSProxy doesNotRecognizeSelector"...]"

I'm using OCMock trying to test the behavior of NSURLConnection. Here's the incomplete test: #include "GTMSenTestCase.h" #import @interface HttpTest : GTMTestCase - (void)testShouldConnect; @end @implementation HttpTest -…
Hans Sjunnesson
  • 21,745
  • 17
  • 54
  • 63
2
votes
1 answer

Is it possible to use OCMock with NSURLConnection to inject simulated server response data?

I've spent all afternoon trawling the web for tutorials and examples of using OCMock but I've still no idea if its possible and if so how to use it in combination with NSURLConnection to set up test code to simulate a server sending data in response…
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
2
votes
2 answers

How to unit test NSFetchedResultsControllerDelegate?

I am trying to write unit tests for a view controller that implements the NSFetchedResultsControllerDelegate protocol. The first test of the implementation (after some other tests of this view controller) is to verify that a table row is inserted…
Jorge Ortiz
  • 1,556
  • 1
  • 16
  • 19
2
votes
1 answer

How do I properly test this method with OCMock?

I'm new to OCMock and i'm trying to test if a method is called, except I want the method to be a stub since it contains other loading methods I do not care to test in the current test. - (void)setUp { self.rootViewController =…
Josh Jones
  • 498
  • 1
  • 4
  • 8
2
votes
2 answers

Why does OCMock cause nsnotificaiton center to have EXC_BAD_ACCESS when using mockObserver

I setup mock observers like this: id quartileObserverMock = [OCMockObject observerMock]; [[NSNotificationCenter defaultCenter] addMockObserver:quartileObserverMock …
Infrid
  • 336
  • 1
  • 3
  • 13
2
votes
2 answers

Is there a way to easily run a specific group of tests or a single test in xcode?

Is there a way to run a single test in isolation, or a group of tests? I find that when I am trying to debug a particular test, it's really annoying because previous test cases may trigger that same break point-- So I typically comment out all my…
patrick
  • 9,290
  • 13
  • 61
  • 112
2
votes
1 answer

OCMock on category

I'm trying to set up some test cases for a simple UIDevice category I've created. Since these methods are instance methods, I have created a mock to emulate the currentDevice behavior. The added methods are based on the name attribute so I've…
2
votes
2 answers

How can I mock the isEditing getter on UITextField?

I've been trying to mock a simple property on UITextField: @property(nonatomic,readonly,getter=isEditing) BOOL editing; I've tried to mock this 2 ways 1.) using the full blown class method swizzle technique (usually for class based methods I'll do…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
2
votes
1 answer

OCMock valueForKey failing with NSPredicate

In the code I'm testing, I have an NSPredicate and I'm filtering an array: NSPredicate* predicate = [NSPredicate predicateWithFormat:@"status == %d || status == %d", FVFileReadyStatus, FVFileWaitingStatus]; [myArray…
Tim Reddy
  • 4,340
  • 1
  • 40
  • 77
1
vote
1 answer

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

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. -…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
1
vote
1 answer

How to debug an NSPredicate that is failing with mocked objects?

I have a core data application that uses an NSPredicate in one of its fetch requests. That predicate is defined as follows: NSDictionary *teamsParams = [NSDictionary dictionaryWithObject:teamArray forKey:@"TEAMS"]; NSPredicate *predicate =…
Tim Dean
  • 8,253
  • 2
  • 32
  • 59
1
vote
1 answer

Is it possible to 'expect' a method from a partial mock

It is not the best thing to do, but I would like to verify that a private method of an object is called, so I create a partial mock and add an expectation on the private method. Synchronizer * sync = [[Synchronizer alloc] initWithCleanup:YES]; sync…
Quentin
  • 1,741
  • 2
  • 18
  • 29
1
vote
1 answer

How can I unit test this hitTest override in iPhone?

How can I unit test this hitTest override? - (UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView* hitView = [super hitTest:point withEvent:event]; // Do something based on hitView's properties } The problem I'm facing is…
hpique
  • 119,096
  • 131
  • 338
  • 476
1
vote
2 answers

EXC_BAD_ACCESS with partialMockForObject and a UIView

I've got some troubles with OCMock and UIView. I have sort of this code: UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; id view1Mock = [OCMockObject partialMockForObject:view1]; [[[view1Mock expect] andForwardToRealObject]…
kiecodes
  • 1,642
  • 14
  • 28
1
vote
1 answer

Objective-C - Mocking a segmented control using OCMock?

I am trying to mockj a segmented control and I am getting crashes, any suggestions? NSInteger selectedSegment = 2; id segmentedControlMock = [OCMockObject niceMockForClass:[UISegmentedControl class]]; [[[segmentedControlMock stub]…
aryaxt
  • 76,198
  • 92
  • 293
  • 442