ocmock

Using a struct with OCMock or Hamcrest

I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with a Hamcrest matcher. No die. The function/method I'm testing looks something like this: -...

Testing use of NSURLConnection with HTTP response error statuses

I'm writing an iPhone application that needs to get some data from a web server. I'm using NSURLConnection to do the HTTP request, which works well, but I'm having trouble unit testing my code in the case where the response has an HTTP error code (like 404 or 500). I'm using GTM for unit testing and OCMock for mocking. When the server ...

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 *)context { Destination * dest = [[Destination alloc] initWithContext:context]; if (conte...

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 mockTabController = [OCMockObject mockForClass:[UITabBarController class]]; [[[mockTabCont...

How do i mock a method that accepts a handle as an argument in OCMock?

I'm trying to mock a method that has the equivalent of the following signature: - (NSDictionary *) uploadValues:(BOOL)doSomething error:(NSError **)error I want it to return a small dictionary so that my test can make sure the code uses the dictionary properly. however, no matter what i do OCMock always returns nil from the method, r...

Prefer Dependency-Injection over Partial Mocking?

I know this SO question, but it deals with the subject in more general terms. Should I prefer using partial Mocks over Dependency Injection? My question is based on the following quote from OCMock: id aMock = [OCMockObject partialMockForObject:anObject] Creates a mock object that can be used in the same way as anObject. When a ...

OCMock returning values

Hey all, I'm trying to write a test for a method where the output depends on an NSDate's timeIntervalSinceNow return value. I'd like to specify the return value in my tests so I can test certain scenarios. I'm having a really hard time getting this OCMock object returning what I'd like. Here's my code: id mock = [OCMockObject mockForC...

Using OCMock to expect category methods yields "[NSProxy doesNotRecognizeSelector"...]"

I'm using OCMock trying to test the behavior of NSURLConnection. Here's the incomplete test: #include "GTMSenTestCase.h" #import <OCMock/OCMock.h> @interface HttpTest : GTMTestCase - (void)testShouldConnect; @end @implementation HttpTest - (void)testShouldConnect { id mock = [OCMockObject mockForClass:[NSURLConnection class]]; ...

How to stub a class method in OCMock?

I often find in my iPhone Objective-C unit tests that I want stub out a class method, e.g. NSUrlConnection's +sendSynchronousRequest:returningResponse:error: method. Simplified example: - (void)testClassMock { id mock = [OCMockObject mockForClass:[NSURLConnection class]]; [[[mock stub] andReturn:nil] sendSynchronousRequest:nil ...

OCMock with Core Data dynamic properties problem

I'm using OCMock to mock some Core Data objects. Previously, I had the properties implemented with Objective-C 1.0 style explicit accessors: // -- Old Core Data object header @interface MyItem : NSManagedObject {} - (NSString *) PDFName; - (void) setPDFName:(NSString *)pdfName; @end // -- implementation provides generated implementatio...

iphone OCMockObject and unit-testing a class that inherits from NSURLConnection

I want to unit test the custom init method of a class that inherits from NSURLConnection -- how would I do this if the init of my testable class invokes NSURLConnection's initWithRequest? I'm using OCMock and normally, I can mock objects that are contained within my test class. For this inheritance scenario, what's the best approach to ...

Not feasible to call NSInvocation from a SenTestCase derived class?

Is NSInvocation class not meant to be called via unit tests (for iPhone)? My intent is to call a class's method generically and since the method has more than 2 parameters, I can't use [myTestClass performSelector:withObject:withObject] Instead, I'm trying to use NSInvocation but as soon as I try to instantiate from NSInvocation class,...

OCMock on a method with argument and returns a value

I have a class that relies on NSUserDefaults that I'm trying to unit-test and I'm providing the NSUserDefaults as a mock into my test class. When running the test, I get the error: OCMockObject[NSUserDefaults]: unexpected method invoked: dictionaryForKey:@"response" I'm trying to mock this instance method of the NSUserDefaults ...

Testing controller method with OCMock and Core Data

I am just grasping the concepts of TDD and mocking, and am running into an issue in terms of how to properly. I have a sheet that drops down and lets a user create a new core data object and save it to the data store. I am not sure if I am taking the best approach to testing it. - (IBAction)add:(id)sender { NSString *itemName = [...

OCMock test fails to build: Foundation/Foundation.h : No such file or directory

Hi, I am a Xcode beginner, and am facing some problems in compiling an OCMock test. I have added the OCMock.framework in "Groups & Files", and then added a very basic OCMock test from the Unit testing target, basically for Canary testing. When I compile the OCMockTests.m file, the system returns around 38 errors pointing out all the i...

How to use mock and verify methods of OCMock in objective-C ? Is there any good tutorial on OCMock is available on the internet?

My problem is I am getting an error: OCMckObject[NSNumberFormatter]: expected method was not invoked:setAllowsFloats:YES I have written following Code: (void) testReturnStringFromNumber { id mockFormatter = [OCMockObject mockForClass:[NSNumberFormatter class]]; StringNumber *testObject = [[StringNumber alloc] init]; ...

How can I use OCMock to verify that a method is never called?

At my day job I've been spoiled with Mockito's never() verification, which can confirm that a mock method is never called. Is there some way to accomplish the same thing using Objective-C and OCMock? I've been using the code below, which works but it feels like a hack. I'm hoping there's a better way... - (void)testSomeMethodIsNeverCal...

OCmock and MKReverseGeocoder

Hi, I would like to test a method that uses reverse Geocoding. What i would like to do is : set the geocoder as a property of my controller create the geocoder in the init method call the geocoder in the method i want to test replace the geocoder with a mock in my test The problem is that the MKReverseGeocoder coordinate property is...

How can i have OCMock send parameter to a method ?

Hi, I need to test a method that calls a webservice. So i want to mock the webservice class using OCMock. What i would like to do is tell my mock : when i try to call my webservice just forward the call to the didSucceed method and send it mock datas. I can forward the call to the success method without problems using : [[[myMock stub...

OCMock on iOS 4

I've been having troubles to run OCMock with iOS 4. I've read that a possible solution os to build the library, and install libOCMock.a, but honestly, i don't know how. Any help would be usefull ...