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

OCMock of class with method called from the test method

I am trying to test a method that instantiates an instance of MFMailComposeViewController. The method being tested calls several methods of MFMailComposeViewController including setSubject:. I want to test that setSubject is sent a specific…
zaph
  • 111,848
  • 21
  • 189
  • 228
1
vote
1 answer

OCMock/OCMVerify - Expression result unused

Calls like the following don't compile because of Expression result unused warning/error: id object = [Foo new]; id mockObject = OCMPartialMock(object); ... OCMExpect([mockObject doTheThing]); ... OCMVerify(mockObject); Tested on Xcode 12 GM: $…
Matt Robinson
  • 799
  • 7
  • 22
1
vote
1 answer

Is there a way to test an instance variable in objective c?

I need to test an instance variable in Objective C. I have this snippet in myViewController.m @implementation myViewController { NSView *myView; } I need to add a test in myViewControllerTest.mm that tests a case when myView.window happens to be…
zazky
  • 45
  • 1
  • 6
1
vote
1 answer

OCMock throwing NSInternalInconsistencyException when parameters are not the ones expected

I'm setting up a mock object for a delegate object, to check that when the URL is nil, the delegate method is called with nil as parameters. When the FileDownloadOperation behave as expected,the test pass, which is fine. When the…
Raphaël Mor
  • 356
  • 2
  • 14
1
vote
2 answers

OCMock - How to expect the content of an nsarray

I want to test that the values i insert in a database are sent back to the delegate of my class. I tried to mock the delegate and expect the array i used to populate the database. It fails because the 2 NSArray have the same content but are…
vdaubry
  • 11,369
  • 7
  • 54
  • 76
1
vote
1 answer

Testing NSWidowController using OCMock

I've been trying to come up with a a way to unit test my applicationDidFinishLaunching delegate using OCMock. My NSWindowController is instantiated here and I'd like to test it. Here's my test code: id mockWindowController = [OCMockObject…
Lazloman
  • 41
  • 1
  • 3
1
vote
1 answer

How to partial mock objects of the same class twice in OCMock 3.4.2?

EKSource *source1 = [[EKSource alloc] init]; EKSource *source2 = [[EKSource alloc] init]; id source1Mock = OCMPartialMock(source1); [[[source1Mock stub] andReturnValue:@(EKSourceTypeBirthdays)] sourceType]; id source2Mock =…
harshith__
  • 447
  • 3
  • 15
1
vote
1 answer

OCMock3 Integration Issue with IOS

enter image description here I added OCMock framework in my project and I wasn't able to take test Success or fail and code coverage. I got Error like "Error Generating Code Coverage" Anybody knows OCMock Integration with steps please help in…
Red Apple
  • 23
  • 6
1
vote
1 answer

How to stub a class method with response block using OCMock

HTTPResult *successResult = [[HTTPResult alloc] init]; successResult.success = YES; successResult.content = @{@"key":@"value"}; id httpMock = OCMClassMock([HTTPUtility class]); OCMStub(ClassMethod([httpMock…
chenfeng
  • 93
  • 7
1
vote
1 answer

OCMock and overriding stub value

mockModule = OCMPartialMock(module); OCMStub([mockModule send:@"FOO"]).andReturn(YES); OCMStub([mockModule send:@"FOO"]).andReturn(NO); In this example I have a simple mock module, and I set some stubs to return YES/NO when sent a String, the…
xceph
  • 1,036
  • 2
  • 13
  • 28
1
vote
2 answers

Checking IBOutlet connection with OCMock

I want to verify with unit tests that all the IBoutlets in my controller class are correctly hooked up in the NIB file. I'd like to do this with OCMock - even though I know I could simply assert the controllers variables are not nil after loading…
Daniel Schneller
  • 13,728
  • 5
  • 43
  • 72
1
vote
1 answer

Do you know about a good OCMock with GHUnit tutorial in the iPhone / iPad?

I'm using GHUnit in my project and i need learn about OCMock for complete my Unit Tests (but i am new to this). I'm working with xcode 3.2.5 somebody knows about a good tutorial on OCMock? Thanks.
Guerrix
  • 198
  • 1
  • 3
  • 13
1
vote
1 answer

Using primitive type parameter in OCMVerify

I am using OCMock as a mocking framework in my iOS project. When I try to use OCVerify functionality to test that a certain method is invoked, I came across a problem of passing primitive types as parameters. Here is an example to show problem: 1-)…
haven-way
  • 113
  • 1
  • 10
1
vote
2 answers

OCMock: Why do I get an unrecognized selector exception when attempting to call a UIWebView mock?

Edit: This was all caused by a typo in my Other Link Flags setting. See my answer below for more information. I'm attempting to mock a UIWebView so that I can verify that methods on it are called during a test of an iOS view controller. I'm using…
Greg
  • 33,450
  • 15
  • 93
  • 100
1
vote
1 answer

Stubbing blocks in method OCMock

I am facing some hard time in mocking a block inside one of my methods which i want to test. Below is more or less how my code looks like - (void) startFetching:(MyParameter *) parameter { self.fetcher = [[MyFetcher alloc] initWithContext:xxxx…
Madu
  • 4,849
  • 9
  • 44
  • 78