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
6
votes
1 answer

OCMock doesn't stub NSBundle method

I'm using since recently OCMock for my unit testing. I need to stub the objectForInfoDictionaryKey: method from NSBundle. I've done the following : self.bundleMock = OCMClassMock([NSBundle class]); OCMStub([self.bundleMock…
Loadex
  • 1,502
  • 1
  • 12
  • 25
6
votes
2 answers

OCMock and NSFileManager

I am trying to unit test a method which uses NSFileManager to check if a file exists and delete the file. I'm not sure I am correctly setting up the mock object. I'm getting "Method was not invoked" even though I'm certain it was. Am I missing…
Caroline
  • 311
  • 1
  • 9
6
votes
2 answers

OCMock expect and return gives signature error

I have a method of the followng signature; - (NSInteger) getFirstVisitTimeStamp; When I use OCMock to mock and return a value, the test fails with the below error. [[[[YSNYI13NMockingTest mockedYI13N] expect] andReturnValue:@(12345)]…
mohkhan
  • 11,925
  • 2
  • 24
  • 27
6
votes
2 answers

OCMock "expected method was not invoked" even though I'm calling it myself

I'm trying to set up a simple OCMock unit test in an iOS project, just to familiarize myself with the framework. I have a mocked DataLoader class, and even though I'm calling the method myself, my expectation fails: - (void)testSimpleMocking { …
Craig Otis
  • 31,257
  • 32
  • 136
  • 234
6
votes
1 answer

Adding OCMock causes Test to launch main app instead of running tests

I'm trying to add OCMock to my existing Cocoa project, but am running to a strange problem that I don't see anyone else cover. I finally isolated it to the following: if I simply add OCMock.framework reference to my project (i.e. drag it in somehow…
SilverSideDown
  • 1,162
  • 11
  • 14
6
votes
1 answer

How can i get OCMock to let me stub a category method on a UIKit class?

I'm trying to mock a UITabBarController in my app's tests. I have a category method on that class defined elsewhere in another file that gets imported along with ocmock in my test class. what i'm trying to so is this: - (void) setUp { id…
Kevlar
  • 8,804
  • 9
  • 55
  • 81
6
votes
4 answers

How can i unit test an object internal to a method in Objective-C?

I'm wondering how to go about testing this. I have a method that takes a parameter, and based on some properties of that parameter it creates another object and operates on it. The code looks something like this: - (void) navigate:(NavContext…
Kevlar
  • 8,804
  • 9
  • 55
  • 81
6
votes
2 answers

How to I capture an argument sent to a mock?

Does anyone know how to capture an argument sent to an OCMock object? id mock = [OCMockObject mockForClass:someClass] NSObject* captureThisArgument; [[mock expect] foo:] [mock foo:someThing] GHAssertEquals[captured, someThing,…
Dr Joe
  • 718
  • 5
  • 19
5
votes
1 answer

OCMock Failing at runtime

I'm trying to use OCMock for the first time in my test cases. It's a Mac project, built on and targeting Lion, in Xcode 4.3. The main app and the test bundle both have ARC turned on, and so every time I execute the tests I see the following log…
Dov
  • 15,530
  • 13
  • 76
  • 177
5
votes
2 answers

How to mock class method (+)?

Need to write unit testing for the following code, I want to do mock for class method canMakePayments, return yes or no, so far no good method found dues to canMakePayments is a class method (+), seems all OCMock methods are all used for instance…
jianhua
  • 1,011
  • 1
  • 12
  • 28
5
votes
1 answer

How to init an object with stubbed values with OCMock

Ho do I stub a method used in the init method? The related methods in my class: - (id)init { self = [super init]; if (self) { if (self.adConfigurationType == AdConfigurationTypeDouble) { [self…
mOp
  • 385
  • 3
  • 9
5
votes
1 answer

Test Core Data Application

How should I test the findByAttribute instance method I added to NSManagedObject? At first, I thought of programmatically creating an independent Core Data stack as demonstrated by Xcode's Core Data Utility Tutorial. And, in my search for that…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
5
votes
2 answers

Objective C - Unit testing & Mocking object?

- (BOOL)coolMethod:(NSString*)str { //do some stuff Webservice *ws = [[WebService alloc] init]; NSString *result = [ws startSynchronous:url]; if ([result isEqual:@"Something"]) { //More calculation return…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
5
votes
1 answer

How to use OCMock to verify that an asynchronous method does not get called in Objective C?

I want to verify that a function is not called. The function is executed in an asynchronous block call inside the tested function and therefore OCMReject() does not work. The way I have tested if async functions are indeed called would be as…
Bennie
  • 339
  • 2
  • 12
5
votes
1 answer

OCMock and UIViewController

I am currently researching on how to efficiently add some unit tests to my app's ViewControllers. So far it worked pretty well until I tried to that that a specific view controller presents another one. I am using OCMock and XCTest. The test is as…