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

Unit test an action on UITextField

I have a simple if condition that, when met, adds a target to drop the keyboard when "Done" is tapped - (void)addDoneWhenTrue:(UITextField *)input { if (YES) { [input addTarget:self action:@selector(textFieldFinished:)…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
3
votes
1 answer

OCMock is only effective once, strange, why? Or what's wrong on my side?

I want to do mock for TnSettings, yes, it works if code by the following method, the problem is that we need to do write mock code for each case, if we only mock once then execute more than one case, then the second will report exception. I use the…
jianhua
  • 1,011
  • 1
  • 12
  • 28
3
votes
1 answer

iOS Unit testing private mock objects?

In my XCode project I have: controller (Singleton) databaseController The databaseController is instantiated within the controller class. How do I replace this databaseController with a mock object to verify proper functioning of the controller…
2
votes
1 answer

forward declaration error when converting OCMock class to ARC

I just upgraded to Xcode version 4.3.2 (4E2002). I'm converting a mock class from manual memory management to ARC. The code looks like this: @implementation OCProtocolMockObject - (id)initWithProtocol:(Protocol *)aProtocol { [super init]; …
nont
  • 9,322
  • 7
  • 62
  • 82
2
votes
3 answers

How to stub out / inject a view controller for state based testing on the iOS 5 runtime?

I'm looking for a "best practice" / "low test friction" way to do state based testing on view controllers inside my base AppDelegate class. Currently the below provides an easy way to stub in my own UIViewController (using ocmock) when something…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
2
votes
2 answers

Using partialMockForObject to do singleton class mock, how to create a method like "removeAllExpectations” to remove all remembered ones?

Confused on OCMock for singleton, get two methods, but none of them is perfect in my opinion. Using partialMockForObject. I want to use partialMockForObject to do singleton class mock. See following code, it works well, but the defect is that…
jianhua
  • 1,011
  • 1
  • 12
  • 28
2
votes
2 answers

Why do my OCMock expects and stubs fail in iOS 5?

I have some simple mock objects with some stubs and expectations set up. When I run my tests on the iOS 4.3 simulator, everything passes. When I run on iOS 5, I get "unexpected method invoked" failures. As an example case, I have a method -…
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
2
votes
1 answer

OCMock testing the address of a struct

I have some code I want to test that is passing around the address of a struct: MyObject myObject = ...; MyRecord record = [someObject record]; //record is a @property [myObject add:&record]; I've mocked someObject to return a record: MyRecord…
Tim Reddy
  • 4,340
  • 1
  • 40
  • 77
2
votes
1 answer

Test if a function is called in Unit Testing for Objective C

In the implementation file (.mm) I have a function that calls different APIs depending on the value of a boolean isTrue which is set in other APIs @implementation Controller -(void) setProperty:(Id)Id value:(NSObject*)value { if(value) { …
2
votes
0 answers

How can I get a nested objective-c async method to execute under test using mocks and expectations?

Here is my test - (void)test_IsOverLimit { id myCoordinator = OCMPartialMock([[MyCoordinator alloc] init]); XCTestExpectation *expectationLimitResult = [self expectationWithDescription:@"my limit result"]; [myCoordinator…
Jamie M.
  • 590
  • 1
  • 8
  • 16
2
votes
2 answers

Objective C - OCMock and stubbing?

Is it possible to have an actual object of a class and only mock a method in that class instead of mocking the whole object? I want the object to behave 100% the same as the real object except 1 method. Ex: MyObject *object = [[MyObject alloc]…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
2
votes
1 answer

Objective C - How to use OC Mock?

I have a class that suppose to return a string when a method gets called. How can i create a mock object. I want mock to return @"Hello" when the method "sayHello" get's called id mock = [OCMockObject mockForClass:[MyCrazyClass class]];
aryaxt
  • 76,198
  • 92
  • 293
  • 442
2
votes
1 answer

OCMock: return the same value as get by parameter

I have faced with a bit specific issue while writing unit tests with the OCMock framework. Let's say I have some method with one parameter. What I need is to stub that method and get the same value back. The value is calculated, so I can't just…
Oleshko
  • 2,923
  • 4
  • 17
  • 25
2
votes
2 answers

Swift Unit test case - Mock framwork

I want to use mock framework for swift language in iOS. I have used OCMock framework for Objective C, But same was not working in swift. So, I need proper frameworks for handling mock object in swift.
2
votes
1 answer

How to mock a class method of NSObject using OCMock

Is there a way to create an instance of an NSObject? I'm trying to mock a class method from NSObject and am getting an error that objc[86140]: no class for metaclass 0x1065c0e38. - (void)testChainMethodCalled { id controller = [OCMockObject…
stumped
  • 3,235
  • 7
  • 43
  • 76