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

XCode - iOS - file not found

I Have an iOS application that I am trying to add OCMock to in order to better unit test it. I've followed the instruction on ocmock.org as well as instructions I've found in other places but still I cannot get my test code to compile. Here's…
Vince613
  • 329
  • 7
  • 18
8
votes
1 answer

OCMock, why can't I expect method on a protocol?

Consider this code, which works (the loginWithEmail method gets expected as, well, expected): _authenticationService = [[OCMockObject mockForClass:[AuthenticationService class]] retain]; [[_authenticationService expect] loginWithEmail:[OCMArg any]…
driis
  • 161,458
  • 45
  • 265
  • 341
8
votes
1 answer

What is the difference in OCMock expect and stub methods?

I am trying to use OCMock for testing my app. But I am confused where should we use expect and where to use stub? Can anyone help please?
sanjana
  • 203
  • 2
  • 5
7
votes
3 answers

Delayed OCMock verify / Dealing with Timeout in Unit Tests

I'm testing real web service calls with OCMock. Right now I'm doing something like: - (void)testWebservice { id mydelegatemock = [OCMockObject mockForProtocol:@protocol(MySUTDelegate)]; [[mydelegatemock expect] someMethod:[OCMArg any]]; …
fabb
  • 11,660
  • 13
  • 67
  • 111
7
votes
2 answers

Using OCMock 1.77 for Unit and Application Test with iOS4 and Xcode 4/SDK4.3

I am trying to use OCMock 1.77 for unit and application testing with iOS4 and Xcode 4/SDK4.3. I have followed the instructions to do using OCMock as a static library found here: http://www.mulle-kybernetik.com/software/OCMock/. The unit and…
Erik
  • 7,479
  • 8
  • 62
  • 99
7
votes
1 answer

OcMock vs OcMockito - what are pros and cons

For iOS tdd testing/mocking which framework would you recommend? I heard that OcMock has been around longer and is more lightweight. Could anyone provide a few examples of the pros and cons or demo some strengths of each. I'm just looking for a…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
7
votes
4 answers

Testing if performSegueWithIdentifier is called within a view controllers method

I am going through an application and adding Unit Tests. The application is written using storyboards and supports iOS 6.1 and above. I have been able to test all the usual return methods with no problem. However I am currently stumped with a…
Rob
  • 1,233
  • 13
  • 24
7
votes
2 answers

How to start with OCMock and check if method was invoked

I'm trying to deal with OCMock. I created simple class MyClass. @interface MyClass : NSObject - (NSString *)simpleMethod; @end @implementation MyClass - (NSString *)simpleMethod { [self method]; return @"simple"; } - (void)method { …
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
7
votes
2 answers

OCMock - verifying order of method calls. Is there any other way?

When I want to verify that in one method a mock object is receiving some messages in a particular order I do something like this: // sut is an instance of the class I am testing and myMock is a mock object injected in sut. // I want to test that…
e1985
  • 6,239
  • 1
  • 24
  • 39
7
votes
2 answers

OCMock: Mocking protocols with excluding optional methods

I'm using OCMock for creating mocks in my tests for my iOS app, and I'd like to create mocks of protocols that don't implement all of the optional methods. If it's not clear what I mean... here's some code: // Protocol definition @protocol…
extremeboredom
  • 1,512
  • 12
  • 13
7
votes
1 answer

Mocking a method in OCMock for all instances of a class

I want to mock an instance method for all instances of a class using OCMock however I don't have the instance of the class to override it rather it is created inside the method that I'm testing. So my question is: is it possible to override this…
wibosco
  • 967
  • 1
  • 11
  • 32
6
votes
1 answer

Testing void methods using OCMock in iOS

I am trying to write a test case for a method in Objective-C class which returns void. The method mobileTest just creates another object of class AnotherClass and calls a method makeNoise. How to test this ? I tried to use OCMock to create test…
Nilesh Agrawal
  • 3,002
  • 10
  • 26
  • 54
6
votes
3 answers

ocmock's invokeBlockWithArgs using a nil argument

is there any way to invoke a block with nil as a given argument, given that the invokeBlockWithArgs: requires the args to be nil-terminated? example method definition in a mocked object: - (void)methodWithCompletion:(void(^)(NSString*, NSError* ))…
cyrix
  • 308
  • 2
  • 7
6
votes
3 answers

How to unit-test an internet protocol implementation?

I decided to add unit tests to my project and continue development in a test-driven kind of way. I’m currently working on implementing unit tests for my ManageSieve client object and I’m not sure what’s the best way to test that beast. My…
Sven
  • 22,475
  • 4
  • 52
  • 71
6
votes
1 answer

Unit Testing with NSURLSession for OCMock

I have a networking class called: ITunesAlbumDataDownloader @implementation AlbumDataDownloader - (void)downloadDataWithURLString:(NSString *)urlString completionHandler:(void (^)(NSArray *, NSError *))completionHandler { …
GameDev
  • 445
  • 7
  • 21
1 2
3
32 33