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

Test rig exited abnormally with code 134 with OCMock verify on iOS 4

I'm trying to add OCMock to my iOS 4 project. To test it out, I have a class Person with one method, -hello. When I run this test: - (void) testMock { id mock = [OCMockObject mockForClass:[Person class]]; [[mock expect] hello]; [mock…
bsstokes
  • 63
  • 1
  • 7
3
votes
1 answer

OCMock mocking UIImagePickerController

I'm trying to mock UIImagePickerController to test method from ViewController (written in Swift): var imagePicker: UIImagePickerController! ... func choosePhoto() { imagePicker = UIImagePickerController() imagePicker.delegate = self …
jonaszmclaren
  • 2,459
  • 20
  • 30
3
votes
3 answers

OCMock for iPhone (iOS4, XCode 3.2.3)

I have the last version of OCMock (1.55) and XCode 3.2.3. I have created a test bundle target in my project. What is the best way to use OCMock in my tests? When I add OCMock.framework to the test bundle, this build error appears: …
alexey
  • 8,360
  • 14
  • 70
  • 102
3
votes
1 answer

Unit testing with `OCMock`

I want to cover MYImageLoader class with unit tests using OCMock. On of the tests makes sure that when it downloads an image it copies the file from the location returned in a NSURLSessionDownloadTask callback to a temporary location. And here I am…
dariaa
  • 6,285
  • 4
  • 42
  • 58
3
votes
3 answers

Is it possible to use OCMock to mock both class methods and a protocol?

In the OCMock docs you can easily mock a class, OR a protocol: id classMock = OCMStrictClassMock([SomeClass class]); id protocolMock = OCMStrictProtocolMock(@protocol(SomeProtocol)); My question is: can you do both? Basically I want to mock out an…
abbood
  • 23,101
  • 16
  • 132
  • 246
3
votes
2 answers

OCMock: Mock objects that implement several protocols?

id protocolMock = OCMProtocolMock(@protocol(SomeProtocol)); Will create a mock object that can be used as if it were an instance of an object that implements SomeProtocol. Does OCMock provide a way to create a mock object that implements several…
schmittsfn
  • 1,412
  • 18
  • 40
3
votes
1 answer

OCMock mock protocol's static class method.

New in OCMock 3 is the ability to mock out class methods. Is it possible to mock class methods defined in a protocol? i.e @protocol AViewControllerProtocol + (Type)typeForViewController; @end Inside my unit test class -…
ajmccall
  • 2,024
  • 23
  • 42
3
votes
1 answer

How to unit test custom implementation of drawRect

I am trying to write a test/s using XCTest to drive out the implementation of a custom implementation of the drawRect method and am unsure how to do this. The code I am looking to have to write because of a test/s is as follows: -…
3
votes
0 answers

OCMVerify and Undefined symbols for architecture i386/armv7/armv7s

I am using OCMock (version 3.1.1) in my project and I am trying to use the OCMVerify macro to check if some method is called inside my object. The problem is when I put this line: OCMVerify([mockEngine notify]); XCode show me the following link…
3
votes
1 answer

OCMock can't stub a category method

I'm trying to work with a mock of NSMutableURLConnection, but OCMock doesn't want to stub methods declared in the NSHTTPURLRequest category of NSMutableURLConnection. id requestMock = OCMClassMock([NSMutableURLRequest class]); OCMStub([requestMock…
espressoexcess
  • 191
  • 1
  • 3
3
votes
1 answer

Xcode 6, Swift and mock verification without exceptions

Anyone know how to verify an OCMock expect in Swift? Swift Doesn't use Exceptions so XCTest no longer includes XCTAssertNoThrow. Is There any other way to verify a method was called with OCMock? I noticed in OCMock the verify function checks the…
Alex Reynolds
  • 6,264
  • 4
  • 26
  • 42
3
votes
2 answers

OCMock stub isSelected property

I am trying to stub the selected property on UIButton. The getter is defined as: @property (nonatomic, getter=isSelected) BOOL selected; My stub looks like this: [[[button stub] andReturnValue:OCMOCK_VALUE(TRUE)] isSelected]; I receive the…
JFoulkes
  • 2,429
  • 1
  • 21
  • 24
3
votes
1 answer

OCMock Class Method Not Working

I am trying to mock a class method that identifies if the iOS is iOS 6 (or earlier) or iOS 7 (or later). Here is the testing code: id iOSDetectorMock = [OCMockObject mockForClass:[UTiOSVersionDetector class]]; [[[iOSDetectorMock stub]…
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
3
votes
2 answers

OCMock - Unexpected Method Invoked although expected

Here is the tested code: if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailComposeController = [[MFMailComposeViewController alloc] init]; [mailComposeController setSubject:nil]; …
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
3
votes
1 answer

OCMockObserver: unexpected notification observed

NotificationManager.h #import @interface NotificationManager : NSObject -(void)postNotification; @end NotificationManager.m #import "NotificationManager.h" @implementation…
sash
  • 8,423
  • 5
  • 63
  • 74