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

Can OCMock mock a class such that it automatically uses the mocked instance in the code under test without injecting it

I'm new to OCMock and had a question. Can we stub a method of a class, where calling that method over any instance/object of that class gets mocked For Example : if Class_A has a non static function_a and Class_B has function_b which internally…
4
votes
1 answer

iOS - Unit Testing Asynchoronous code

The part of a method that I am trying to test is as follows: - (void)configureTableFooterView { dispatch_async(dispatch_get_main_queue(), ^{ self.tableView.tableFooterView = nil; if ([self.parser.resultSet isLastPage]) { …
4
votes
2 answers

OCMock automatically use mocked instance in code under test?

I am new in OCMock. I use dispatch_once() created a singleton class MyManager : @implementation MyManager + (id)sharedInstance { static MyManager *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ …
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
4
votes
1 answer

OCMock -[NSURLSessionDataTask response] unrecognized selector crash in iOS 9

The problem We use OCMock for mock objects in many of our unit tests. As part of our tests to see how our code responds to server responses, we create an NSURLSessionDataTask object and later try to use the "response" property on it. The plot…
BergQuester
  • 6,167
  • 27
  • 39
4
votes
2 answers

OCMock on iOS 4

I've been having troubles to run OCMock with iOS 4. I've read that a possible solution os to build the library, and install libOCMock.a, but honestly, i don't know how. Any help would be usefull
ariel
  • 143
  • 1
  • 7
4
votes
2 answers

Random crash with OCMock

Sometimes I get a EXC_BAD_ACCESS when running this test: - (void)testThatItDoesNotSaveLoadedImageIfNotIntializedWithModifiesFileCacheOption { id cacheMock = OCMClassMock([BEImageCache class]); id imageLoaderMock =…
dariaa
  • 6,285
  • 4
  • 42
  • 58
4
votes
2 answers

OCMock 3.0.2 linker error with .mm test file

I am using OCMock 3.0.2, which I've installed through cocoapods for my test target: platform :ios, '7.0' xcodeproj 'myProject.xcodeproj' target :myTestTarget do pod 'OCMock', '~> 3.0.2' end link_with "myTestTarget" In my test file (myTest.mm),…
Kevin Liang
  • 206
  • 2
  • 11
4
votes
1 answer

How do I match struct parameters with OCMock?

So I have a method that has the following signature, in a class called PopoverProvider - (void)showPopoverForAction:(MESAction *)action fromRect:(CGRect)rect inView:(UIView *)view onDoneBlock:(MESActionPopoverDoneBlock)block; And I want to verify…
fatuhoku
  • 4,815
  • 3
  • 30
  • 70
4
votes
2 answers

Testing controller method with OCMock and Core Data

I am just grasping the concepts of TDD and mocking, and am running into an issue in terms of how to properly. I have a sheet that drops down and lets a user create a new core data object and save it to the data store. I am not sure if I am taking…
Justin Williams
  • 703
  • 1
  • 9
  • 26
4
votes
3 answers

Unit testing Parse framework iOS

I am attempting to write unit tests for an iOS application which makes use of the Parse backend framework, and after much experimentation seem to be failing at writing successful unit tests. I have found a few posts on testing asynchronous code…
Alex Brown
  • 1,613
  • 1
  • 13
  • 23
4
votes
3 answers

Is there any way to instantiate a prototype UITableViewCell from a storyboard for testing?

I'm using a combination of XCTest and OCMock for testing an iOS application. I'm using a UITableViewController to present a series of prototype cells which I would like to write some tests for. The cell itself is in a storyboard so I don't believe I…
psobko
  • 1,548
  • 1
  • 14
  • 24
4
votes
2 answers

Mock NSHTTPURLRequest and NSHTTPURLResponse in iOS unit test

I'm developing a framework in iOS which makes HTTP calls to server.I wanted to write unit test to test the API's.I wanted to mock the server calls,without actually making real server call.Can anyone help me with sample unit test which makes mocked…
Karthik207
  • 493
  • 9
  • 27
4
votes
2 answers

Can I use OCMock to test whether a super class gets called?

I made a subclass of MKMapView. In unit test, I want to know when I invoke a certain method of this subclass, that a corresponding MKMapView method is invoked and the class of the argument. Can I use OCMock to accomplish this? EDIT: I accepted the…
huggie
  • 17,587
  • 27
  • 82
  • 139
4
votes
1 answer

OCMock expect a class method

So I want to be able to expect a class method being called for one of my classes @implementation CustomClass + (void)method:(NSString*)string{ [[self class] method:string object:nil]; } + (void)method:(NSString *)string object:(id)object { …
Andrew Park
  • 1,489
  • 1
  • 17
  • 26
4
votes
5 answers

cannot stub class method with OCMock 2.1+ in Xcode 5.0

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)…
abbood
  • 23,101
  • 16
  • 132
  • 246